PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.4.3
JetFormBuilder — Dynamic Blocks Form Builder v1.4.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / live-form.php
jetformbuilder / includes Last commit date
actions 4 years ago addons 4 years ago admin 4 years ago blocks 4 years ago classes 4 years ago compatibility 4 years ago dev-mode 4 years ago exceptions 4 years ago form-actions 4 years ago form-messages 4 years ago form-patterns 4 years ago form-response 4 years ago gateways 4 years ago generators 4 years ago integrations 4 years ago presets 4 years ago request 4 years ago shortcodes 4 years ago widgets 4 years ago autoloader.php 4 years ago file-upload.php 4 years ago form-break.php 4 years ago form-handler.php 4 years ago form-manager.php 4 years ago live-form.php 4 years ago plugin.php 4 years ago post-type.php 4 years ago
live-form.php
212 lines
1 <?php
2
3 namespace Jet_Form_Builder;
4
5 use Jet_Form_Builder\Blocks\Types\Base as Block_Type_Base;
6 use Jet_Form_Builder\Classes\Attributes_Trait;
7 use Jet_Form_Builder\Classes\Get_Template_Trait;
8 use Jet_Form_Builder\Classes\Instance_Trait;
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15
16 /**
17 * @method static Live_Form instance()
18 *
19 * Class Live_Form
20 * @package Jet_Form_Builder
21 */
22 class Live_Form {
23
24 use Attributes_Trait;
25 use Get_Template_Trait;
26 use Instance_Trait;
27
28 public $form_id = false;
29 private $form = false;
30
31
32 private $field_name;
33 private $current_field_data;
34 private $start_new_page = true;
35 public $rendered_rows = 0;
36
37 public $is_hidden_row;
38 public $is_submit_row;
39
40 public $current_repeater;
41 public $current_repeater_i;
42 public $preset;
43 public $spec_data;
44 public $post;
45 public $_conditional_blocks = array();
46 public $_repeaters = array();
47 public $blocks = array();
48
49 // for progress
50 public $form_break;
51
52 /**
53 * Create form instance
54 *
55 * @param [type] $form_id [description]
56 */
57 private function __construct() {
58 $this->post = get_post();
59 }
60
61 public function set_form_id( $form_id ) {
62 $this->form_id = $form_id;
63
64 return $this;
65 }
66
67 /**
68 * It turns out the inheritance of such an image
69 * Incoming Form Attributes (from block/widget/shortcode)
70 * (if not) -> Individual Form Arguments
71 * (if not) -> Default PHP Values
72 *
73 * @param array $incoming_attributes
74 *
75 * @return $this
76 */
77 public function set_specific_data_for_render( $incoming_attributes = array() ) {
78 $jf_default_args = Plugin::instance()->post_type->get_default_args();
79 $jf_args = Plugin::instance()->post_type->get_args( $this->form_id );
80
81 $attributes_from_post_type = array_diff( $jf_args, $jf_default_args );
82 $form_block_or_widget = array_diff( $incoming_attributes, $jf_default_args );
83
84 $render_attributes = array_merge( ...apply_filters(
85 'jet-form-builder/form-render/attributes',
86 array(
87 Plugin::instance()->post_type->get_default_args_on_render(),
88 $attributes_from_post_type,
89 $form_block_or_widget
90 )
91 ) );
92
93 $this->spec_data = ( object ) $render_attributes;
94
95 return $this;
96 }
97
98 public function get_spec( $property, $default = '' ) {
99 return ( $this->spec_data->{$property} ?? $default ) ?: $default;
100 }
101
102 public function is_not_field( $block ) {
103 return Plugin::instance()->form->is_not_field( $block['blockName'] );
104 }
105
106 public function is_field( $block, $needle ) {
107 return Plugin::instance()->form->is_field( $block['blockName'], $needle );
108 }
109
110 public function get_fields( $content ) {
111 return Plugin::instance()->form->get_fields( $content );
112 }
113
114 /**
115 * Setup fields prop
116 *
117 * @param $content
118 *
119 * @return array[]
120 */
121 public function setup_fields( $content ) {
122 $blocks = parse_blocks( $content );
123 $this->blocks = $this->get_form_break()->set_pages( $blocks );
124
125 return $this->blocks;
126 }
127
128 public function maybe_progress_pages() {
129 if ( ! $this->spec_data->enable_progress || 0 === $this->get_form_break()->get_pages() ) {
130 return '';
131 }
132
133 return $this->get_form_break()->render_progress( 'default', array(
134 'jet-form-builder-progress-pages--global'
135 ) );
136 }
137
138
139 public static function force_render_field( $name, $arguments = array() ) {
140 if ( empty( $name ) ) {
141 return '';
142 }
143 $field = jet_form_builder()->blocks->get_field_by_name( $name );
144
145 if ( ! $field instanceof Block_Type_Base ) {
146 return '';
147 }
148
149 $field->set_block_data( $arguments, null );
150
151 return $field->get_block_renderer();
152 }
153
154
155 /**
156 * Maybe start new page
157 *
158 * @param bool $force_first
159 *
160 * @return false|string|void
161 */
162 public function maybe_start_page( $force_first = false ) {
163 return $this->get_form_break()->maybe_start_page( $force_first );
164 }
165
166 /**
167 * Maybe start new page
168 *
169 * @param $is_last
170 * @param $field
171 *
172 * @return false|string|void [type] [description]
173 */
174 public function maybe_end_page( $is_last = false, $field = false ) {
175 return $this->get_form_break()->maybe_end_page( $is_last, $field );
176 }
177
178 public function get_nonce_id() {
179 return "jet-form-builder-wp-nonce-{$this->form_id}";
180 }
181
182 /**
183 * @param string $name
184 *
185 * @return Form_Break
186 */
187 public function get_form_break( $name = '' ) {
188 if ( ! $name && ! $this->form_break ) {
189 $this->form_break = new Form_Break();
190 }
191 if ( $name && ! $this->isset_form_break( $name ) ) {
192 $this->_conditional_blocks[ $name ] = array( 'break' => new Form_Break() );
193 }
194
195 return $name ? $this->_conditional_blocks[ $name ]['break'] : $this->form_break;
196 }
197
198 public function isset_form_break( $name ) {
199 return isset( $this->_conditional_blocks[ $name ] );
200 }
201
202 public function get_repeater( $name ) {
203 return $this->_repeaters[ $name ] ?? array();
204 }
205
206 public function set_repeater( $name, $attrs ) {
207 $this->_repeaters[ $name ] = array_merge( $this->get_repeater( $name ), $attrs );
208 }
209
210
211 }
212