PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.4.0
JetFormBuilder — Dynamic Blocks Form Builder v1.4.0
3.6.4 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 / blocks / render / form-builder.php
jetformbuilder / includes / blocks / render Last commit date
action-button-render.php 4 years ago base-select-radio-check.php 4 years ago base.php 4 years ago calculated-field-render.php 4 years ago checkbox-field-render.php 4 years ago date-field-render.php 4 years ago datetime-field-render.php 4 years ago form-break-field-render.php 4 years ago form-builder.php 4 years ago group-break-field-render.php 4 years ago heading-field-render.php 4 years ago media-field-render.php 4 years ago number-field-render.php 4 years ago radio-field-render.php 4 years ago range-field-render.php 4 years ago repeater-field-render.php 4 years ago select-field-render.php 4 years ago submit-field-render.php 4 years ago text-field-render.php 4 years ago textarea-field-render.php 4 years ago time-field-render.php 4 years ago wysiwyg-field-render.php 4 years ago
form-builder.php
291 lines
1 <?php
2
3 namespace Jet_Form_Builder\Blocks\Render;
4
5 use Jet_Form_Builder\Classes\Attributes_Trait;
6 use Jet_Form_Builder\Classes\Get_Template_Trait;
7 use Jet_Form_Builder\Classes\Tools;
8 use Jet_Form_Builder\Compatibility\Jet_Style_Manager;
9 use Jet_Form_Builder\File_Upload;
10 use Jet_Form_Builder\Live_Form;
11 use Jet_Form_Builder\Plugin;
12 use Jet_Form_Builder\Presets\Preset_Manager;
13 use JET_SM\Gutenberg\Style_Manager;
14
15 // If this file is called directly, abort.
16
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 /**
22 * Form builder class
23 */
24 class Form_Builder {
25
26 use Attributes_Trait;
27 use Get_Template_Trait;
28
29 public $form_id;
30 public $post;
31 public $args = array();
32
33 private $form_content;
34
35 /**
36 * Constructor for the class
37 *
38 * @param null $form_id
39 * @param bool $post
40 * @param array $args
41 */
42 function __construct( $form_id = null, $post = false, $args = array() ) {
43
44 if ( ! $form_id ) {
45 return;
46 }
47 $this->form_id = $form_id;
48 $this->set_form_args( $args );
49
50 if ( empty( $post ) ) {
51 $this->post = get_post();
52 }
53
54 $this->form_content = Plugin::instance()->form->get_form_content( $form_id );
55 }
56
57 /**
58 * @param $arguments
59 */
60 public function set_form_args( $arguments ) {
61 $this->args = array_intersect_key( $arguments, Plugin::instance()->post_type->get_default_args() );
62
63 return $this;
64 }
65
66
67 /**
68 * Returns form action url
69 *
70 * @return [type] [description]
71 */
72 public function get_form_action_url() {
73
74 $action = add_query_arg(
75 array(
76 Plugin::instance()->form_handler->hook_key => Plugin::instance()->form_handler->hook_val,
77 ),
78 home_url( '/' )
79 );
80
81 return apply_filters( 'jet-form-builder/form-action-url', $action, $this );
82
83 }
84
85 /**
86 * Returns form refer url
87 *
88 * @return [type] [description]
89 */
90 public function get_form_refer_url() {
91
92 global $wp;
93
94 $refer = home_url( $wp->request );
95
96 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
97 $refer = trailingslashit( $refer ) . '?' . $_SERVER['QUERY_STRING'];
98 }
99
100 return apply_filters( 'jet-form-builder/form-refer-url', $refer, $this );
101
102 }
103
104 /**
105 * @return mixed|void
106 */
107 public function pre_render() {
108 return apply_filters( 'jet-form-builder/pre-render/' . $this->form_id, false );
109 }
110
111
112 /**
113 * Open form wrapper
114 *
115 * @return string [type] [description]
116 */
117 public function start_form() {
118
119 Plugin::instance()->blocks->enqueue_frontend_assets();
120 $this->render_styles();
121
122 $start_form = apply_filters( 'jet-form-builder/before-start-form', '', $this );
123
124 $start_form .= $this->maybe_render_fonts_block();
125
126 $this->add_attribute( 'class', 'jet-form-builder' );
127 $this->add_attribute( 'class', 'layout-' . Live_Form::instance()->spec_data->fields_layout );
128 $this->add_attribute( 'class', 'submit-type-' . Live_Form::instance()->spec_data->submit_type );
129 $this->add_attribute( 'action', $this->get_form_action_url() );
130 $this->add_attribute( 'method', 'POST' );
131 $this->add_attribute( 'data-form-id', $this->form_id );
132 $this->add_attribute( 'data-layout', Live_Form::instance()->spec_data->fields_layout );
133
134 ob_start();
135 include $this->get_global_template( 'common/start-form.php' );
136 $start_form .= ob_get_clean();
137
138 $start_form .= apply_filters( 'jet-form-builder/after-start-form', '', $this );
139
140 return $start_form;
141 }
142
143 /**
144 * Close form wrapper
145 *
146 * @return string [type] [description]
147 */
148 public function end_form() {
149
150 $end_form = apply_filters( 'jet-form-builder/before-end-form', '', $this );
151 $form_id = $this->form_id;
152
153 ob_start();
154
155 if ( Plugin::instance()->captcha ) {
156 Plugin::instance()->captcha->render( $this->form_id );
157 }
158
159 include $this->get_global_template( 'common/end-form.php' );
160
161 $end_form .= ob_get_clean();
162
163 $end_form .= apply_filters( 'jet-form-builder/after-end-form', '', $this );
164
165 return $end_form;
166 }
167
168 private function render_styles() {
169 if ( Tools::is_elementor_editor() ) {
170 return;
171 }
172 wp_enqueue_style( 'jet-form-builder-frontend' );
173
174 if ( ! Jet_Style_Manager::is_activated() ) {
175 return;
176 }
177
178 wp_add_inline_style(
179 'jet-form-builder-frontend',
180 Plugin::instance()->post_type->maybe_get_jet_sm_ready_styles( $this->form_id )
181 );
182 }
183
184 private function maybe_render_fonts_block(): string {
185 if (
186 ! Jet_Style_Manager::is_activated()
187 || ! method_exists( Style_Manager::get_instance(), 'get_blocks_fonts' )
188 ) {
189 return '';
190 }
191 $fonts = Style_Manager::get_instance()->get_blocks_fonts( $this->form_id );
192
193 if ( ! $fonts ) {
194 return '';
195 }
196
197 $fonts = trim( $fonts, '"' );
198 $fonts = wp_unslash( $fonts );
199
200 return wp_kses(
201 $fonts,
202 array(
203 'link' => array(
204 'href' => true,
205 'rel' => true,
206 ),
207 )
208 );
209 }
210
211
212 /**
213 * Render from HTML
214 *
215 * @param bool $echo
216 *
217 * @return false|string [type] [description]
218 */
219 public function render_form() {
220
221 if ( $this->pre_render() ) {
222 return '';
223 }
224
225 if ( ! $this->preset()->sanitize_source() ) {
226 echo 'You are not permitted to submit this form!';
227
228 return '';
229 }
230
231 $this->form_content = Live_Form::instance()
232 ->set_form_id( $this->form_id )
233 ->set_specific_data_for_render( $this->args )
234 ->setup_fields( $this->form_content );
235
236 $form = $this->start_form();
237
238 $form .= wp_nonce_field( Live_Form::instance()->get_nonce_id(), '_wpnonce', true, false );
239
240 $form .= Live_Form::force_render_field(
241 'hidden-field',
242 array(
243 'field_value' => $this->form_id,
244 'name' => Plugin::instance()->form_handler->form_key,
245 '_static_value' => true,
246 )
247 );
248
249 $form .= Live_Form::force_render_field(
250 'hidden-field',
251 array(
252 'field_value' => $this->get_form_refer_url(),
253 'name' => Plugin::instance()->form_handler->refer_key,
254 '_static_value' => true,
255 )
256 );
257 $form .= Live_Form::force_render_field(
258 'hidden-field',
259 array(
260 'field_value' => Live_Form::instance()->post->ID,
261 'name' => Plugin::instance()->form_handler->post_id_key,
262 '_static_value' => true,
263 )
264 );
265 $form .= Live_Form::instance()->maybe_progress_pages();
266
267 $form .= Live_Form::instance()->maybe_start_page( true );
268
269 foreach ( $this->form_content as $block ) {
270 $form .= render_block( $block );
271 }
272
273 $form .= Live_Form::instance()->maybe_end_page( true );
274 $form .= $this->end_form();
275
276 Live_Form::clear();
277 Preset_Manager::clear();
278
279 return $form;
280 }
281
282 public function preset() {
283 Preset_Manager::instance()->set_form_id( $this->form_id );
284
285 return Preset_Manager::instance();
286 }
287
288 }
289
290
291