PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.0.5
JetFormBuilder — Dynamic Blocks Form Builder v2.0.5
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-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 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
256 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\Compatibility;
7 use Jet_Form_Builder\Classes\Get_Template_Trait;
8 use Jet_Form_Builder\Classes\Http\Http_Tools;
9 use Jet_Form_Builder\Classes\Tools;
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 array $args
40 */
41 public function __construct( $form_id = null, $args = array() ) {
42
43 if ( ! $form_id ) {
44 return;
45 }
46 $this->form_id = $form_id;
47 $this->set_form_args( $args );
48 }
49
50 /**
51 * @param $arguments
52 */
53 public function set_form_args( $arguments ) {
54 $this->args = array_intersect_key( $arguments, Plugin::instance()->post_type->get_default_args() );
55
56 return $this;
57 }
58
59
60 /**
61 * @return mixed|void
62 */
63 public function pre_render() {
64 return apply_filters( 'jet-form-builder/pre-render/' . $this->form_id, false );
65 }
66
67
68 /**
69 * Open form wrapper
70 *
71 * @return string [type] [description]
72 */
73 public function start_form() {
74
75 Plugin::instance()->blocks->enqueue_frontend_assets();
76
77 $start_form = apply_filters( 'jet-form-builder/before-start-form', '', $this );
78
79 $start_form .= $this->maybe_render_fonts_block();
80 $start_form .= $this->render_styles();
81
82 $this->add_attribute( 'class', 'jet-form-builder' );
83 $this->add_attribute( 'class', 'layout-' . Live_Form::instance()->spec_data->fields_layout );
84 $this->add_attribute( 'class', 'submit-type-' . Live_Form::instance()->spec_data->submit_type );
85 $this->add_attribute( 'action', Http_Tools::get_form_action_url() );
86 $this->add_attribute( 'method', 'POST' );
87 $this->add_attribute( 'data-form-id', $this->form_id );
88 $this->add_attribute( 'data-layout', Live_Form::instance()->spec_data->fields_layout );
89
90 ob_start();
91 include $this->get_global_template( 'common/start-form.php' );
92 $start_form .= ob_get_clean();
93
94 $start_form .= apply_filters( 'jet-form-builder/after-start-form', '', $this );
95
96 return $start_form;
97 }
98
99 /**
100 * Close form wrapper
101 *
102 * @return string [type] [description]
103 */
104 public function end_form() {
105
106 $end_form = apply_filters( 'jet-form-builder/before-end-form', '', $this );
107 $form_id = $this->form_id;
108
109 ob_start();
110
111 if ( Plugin::instance()->captcha ) {
112 Plugin::instance()->captcha->render( $this->form_id );
113 }
114
115 include $this->get_global_template( 'common/end-form.php' );
116
117 $end_form .= ob_get_clean();
118
119 $end_form .= apply_filters( 'jet-form-builder/after-end-form', '', $this );
120
121 return $end_form;
122 }
123
124 private function render_styles(): string {
125 if ( wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
126 return $this->get_inline_styles();
127 }
128
129 if ( Tools::is_elementor_editor() ) {
130 return $this->get_inline_styles();
131 }
132
133 wp_add_inline_style(
134 'jet-form-builder-frontend',
135 Plugin::instance()->post_type->maybe_get_jet_sm_ready_styles( $this->form_id )
136 );
137 wp_enqueue_style( 'jet-form-builder-frontend' );
138
139 return '';
140 }
141
142 private function get_inline_styles(): string {
143 return sprintf(
144 '<style id="jet-form-builder-%s-inline-css">%s</style>',
145 $this->form_id,
146 Plugin::instance()->post_type->maybe_get_jet_sm_ready_styles( $this->form_id )
147 );
148 }
149
150 private function maybe_render_fonts_block(): string {
151 if (
152 ! Compatibility::has_jet_sm()
153 || ! method_exists( Style_Manager::get_instance(), 'get_blocks_fonts' )
154 ) {
155 return '';
156 }
157 $fonts = Style_Manager::get_instance()->get_blocks_fonts( $this->form_id );
158
159 if ( ! $fonts ) {
160 return '';
161 }
162
163 $fonts = trim( $fonts, '"' );
164 $fonts = wp_unslash( $fonts );
165
166 return wp_kses(
167 $fonts,
168 array(
169 'link' => array(
170 'href' => true,
171 'rel' => true,
172 ),
173 )
174 );
175 }
176
177
178 /**
179 * Render from HTML
180 *
181 * @return false|string [type] [description]
182 */
183 public function render_form() {
184
185 if ( $this->pre_render() ) {
186 return '';
187 }
188
189 if ( ! $this->preset()->general()->sanitize_source() ) {
190 echo 'You are not permitted to submit this form!';
191
192 return '';
193 }
194
195 $blocks = Live_Form::instance()
196 ->set_form_id( $this->form_id )
197 ->set_specific_data_for_render( $this->args )
198 ->setup_fields();
199
200 $form = $this->start_form();
201
202 // render wp nonce
203 $form .= Live_Form::instance()->get_nonce_field();
204
205 $form .= Live_Form::force_render_field(
206 'hidden-field',
207 array(
208 'field_value' => $this->form_id,
209 'name' => Plugin::instance()->form_handler->form_key,
210 '_static_value' => true,
211 )
212 );
213
214 $form .= Live_Form::force_render_field(
215 'hidden-field',
216 array(
217 'field_value' => Http_Tools::get_form_refer_url(),
218 'name' => Plugin::instance()->form_handler->refer_key,
219 '_static_value' => true,
220 )
221 );
222 $form .= Live_Form::force_render_field(
223 'hidden-field',
224 array(
225 'field_value' => Live_Form::instance()->post->ID ?? - 1,
226 'name' => Plugin::instance()->form_handler->post_id_key,
227 '_static_value' => true,
228 )
229 );
230 $form .= Live_Form::instance()->maybe_progress_pages();
231
232 $form .= Live_Form::instance()->maybe_start_page( true );
233
234 foreach ( $blocks as $block ) {
235 $form .= render_block( $block );
236 }
237
238 $form .= Live_Form::instance()->maybe_end_page( true );
239 $form .= $this->end_form();
240
241 Live_Form::clear();
242 Preset_Manager::clear();
243
244 return $form;
245 }
246
247 public function preset() {
248 Preset_Manager::instance()->set_form_id( $this->form_id );
249
250 return Preset_Manager::instance();
251 }
252
253 }
254
255
256