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