PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.0.1
JetFormBuilder — Dynamic Blocks Form Builder v3.0.0.1
3.6.4.1 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 3 years ago base-select-radio-check.php 3 years ago base.php 3 years ago calculated-field-render.php 3 years ago checkbox-field-render.php 3 years ago date-field-render.php 3 years ago datetime-field-render.php 3 years ago form-builder.php 3 years ago form-hidden-fields.php 3 years ago group-break-field-render.php 3 years ago heading-field-render.php 3 years ago media-field-render.php 3 years ago number-field-render.php 3 years ago radio-field-render.php 3 years ago range-field-render.php 3 years ago repeater-field-render.php 3 years ago select-field-render.php 3 years ago text-field-render.php 3 years ago textarea-field-render.php 3 years ago time-field-render.php 3 years ago wysiwyg-field-render.php 3 years ago
form-builder.php
234 lines
1 <?php
2
3 namespace Jet_Form_Builder\Blocks\Render;
4
5 use Jet_Form_Builder\Blocks\Dynamic_Value;
6 use Jet_Form_Builder\Blocks\Validation;
7 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
8 use Jet_Form_Builder\Classes\Attributes_Trait;
9 use Jet_Form_Builder\Classes\Compatibility;
10 use Jet_Form_Builder\Classes\Get_Template_Trait;
11 use Jet_Form_Builder\Classes\Http\Http_Tools;
12 use Jet_Form_Builder\Classes\Tools;
13 use Jet_Form_Builder\Compatibility\Jet_Plugins_Ajax\Jet_Plugins_Ajax;
14 use Jet_Form_Builder\Live_Form;
15 use Jet_Form_Builder\Plugin;
16 use Jet_Form_Builder\Presets\Preset_Manager;
17 use JET_SM\Gutenberg\Style_Manager;
18
19 // If this file is called directly, abort.
20
21 if ( ! defined( 'WPINC' ) ) {
22 die;
23 }
24
25 /**
26 * Form builder class
27 */
28 class Form_Builder {
29
30 use Attributes_Trait;
31 use Get_Template_Trait;
32
33 public $form_id;
34 public $post;
35 public $args = array();
36
37 private $form_content;
38
39 /**
40 * Constructor for the class
41 *
42 * @param null $form_id
43 * @param array $args
44 */
45 public function __construct( $form_id = null, $args = array() ) {
46
47 if ( ! $form_id ) {
48 return;
49 }
50 $this->form_id = $form_id;
51 $this->set_form_args( $args );
52 }
53
54 /**
55 * Render from HTML
56 *
57 * @return false|string [type] [description]
58 */
59 public function render_form() {
60
61 if ( $this->pre_render() ) {
62 return '';
63 }
64
65 if ( ! jet_fb_preset( $this->form_id )->general()->sanitize_source() ) {
66 echo 'You are not permitted to submit this form!';
67
68 return '';
69 }
70
71 $blocks = Live_Form::instance()
72 ->set_form_id( $this->form_id )
73 ->set_specific_data_for_render( $this->args )
74 ->setup_fields();
75
76 $form = $this->start_form();
77
78 $form .= Form_Hidden_Fields::render();
79
80 $form .= jet_fb_live()->maybe_progress_pages();
81 $form .= jet_fb_live()->maybe_start_page( true );
82
83 foreach ( $blocks as $block ) {
84 $form .= render_block( $block );
85 }
86
87 $form .= jet_fb_live()->maybe_end_page( true );
88 $form .= $this->end_form();
89
90 Live_Form::clear();
91
92 //Preset_Manager::clear();
93
94 return $form;
95 }
96
97
98 /**
99 * @param $arguments
100 *
101 * @return Form_Builder
102 */
103 public function set_form_args( $arguments ): Form_Builder {
104 $this->args = array_intersect_key( $arguments, Form_Arguments::arguments() );
105
106 return $this;
107 }
108
109
110 /**
111 * @return mixed|void
112 */
113 public function pre_render() {
114 return apply_filters( 'jet-form-builder/pre-render/' . $this->form_id, false );
115 }
116
117 /**
118 * Open form wrapper
119 *
120 * @return string [type] [description]
121 */
122 public function start_form() {
123 Plugin::instance()->blocks->enqueue_frontend_styles();
124
125 $start_form = apply_filters( 'jet-form-builder/before-start-form', '', $this );
126
127 $start_form .= $this->maybe_render_fonts_block();
128 $start_form .= $this->render_styles();
129
130 $this->add_attribute( 'class', 'jet-form-builder' );
131 $this->add_attribute( 'class', 'layout-' . jet_fb_live_args()->fields_layout );
132 $this->add_attribute( 'class', 'submit-type-' . jet_fb_live_args()->submit_type );
133 $this->add_attribute( 'action', Http_Tools::get_form_action_url() );
134 $this->add_attribute( 'method', 'POST' );
135 $this->add_attribute( 'data-form-id', $this->form_id );
136 $this->add_attribute( 'data-layout', jet_fb_live_args()->fields_layout );
137 $this->add_attribute( 'enctype', 'multipart/form-data' );
138 $this->add_attribute( 'data-validation-type', jet_fb_live_args()->validation_type );
139 $this->add_attribute( 'data-clear', jet_fb_live_args()->clear );
140 $this->add_attribute( 'novalidate' );
141
142 ob_start();
143 include $this->get_global_template( 'common/start-form.php' );
144 $start_form .= ob_get_clean();
145
146 $start_form .= apply_filters( 'jet-form-builder/after-start-form', '', $this );
147
148 return $start_form;
149 }
150
151 /**
152 * Close form wrapper
153 *
154 * @return string [type] [description]
155 */
156 public function end_form() {
157 Plugin::instance()->blocks->enqueue_frontend_assets();
158
159 $end_form = apply_filters( 'jet-form-builder/before-end-form', '', $this );
160 $form_id = $this->form_id;
161
162 ob_start();
163
164 if ( Plugin::instance()->captcha ) {
165 Plugin::instance()->captcha->render( $this->form_id );
166 }
167
168 include $this->get_global_template( 'common/end-form.php' );
169
170 $end_form .= ob_get_clean();
171
172 $end_form .= apply_filters( 'jet-form-builder/after-end-form', '', $this );
173
174 return $end_form;
175 }
176
177 private function render_styles(): string {
178 if ( wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
179 return $this->get_inline_styles();
180 }
181
182 if ( Tools::is_elementor_editor() ) {
183 return $this->get_inline_styles();
184 }
185
186 wp_enqueue_style( 'jet-form-builder-frontend' );
187 wp_add_inline_style(
188 'jet-form-builder-frontend',
189 Plugin::instance()->post_type->maybe_get_jet_sm_ready_styles( $this->form_id )
190 );
191
192 return '';
193 }
194
195 private function get_inline_styles(): string {
196 return sprintf(
197 '<style id="jet-form-builder-%s-inline-css">%s</style>',
198 $this->form_id,
199 Plugin::instance()->post_type->maybe_get_jet_sm_ready_styles( $this->form_id )
200 );
201 }
202
203
204 private function maybe_render_fonts_block(): string {
205 if (
206 ! Compatibility::has_jet_sm()
207 || ! method_exists( Style_Manager::get_instance(), 'get_blocks_fonts' )
208 ) {
209 return '';
210 }
211 $fonts = Style_Manager::get_instance()->get_blocks_fonts( $this->form_id );
212
213 if ( ! $fonts ) {
214 return '';
215 }
216
217 $fonts = trim( $fonts, '"' );
218 $fonts = wp_unslash( $fonts );
219
220 return wp_kses(
221 $fonts,
222 array(
223 'link' => array(
224 'href' => true,
225 'rel' => true,
226 ),
227 )
228 );
229 }
230
231 }
232
233
234