PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.3
JetFormBuilder — Dynamic Blocks Form Builder v3.1.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 / blocks / render / form-builder.php
jetformbuilder / includes / blocks / render Last commit date
action-button-render.php 2 years ago base-select-radio-check.php 2 years ago base.php 2 years ago calculated-field-render.php 2 years ago checkbox-field-render.php 2 years ago date-field-render.php 2 years ago datetime-field-render.php 2 years ago form-builder.php 2 years ago form-hidden-fields.php 2 years ago group-break-field-render.php 2 years ago heading-field-render.php 2 years ago media-field-render.php 2 years ago number-field-render.php 2 years ago radio-field-render.php 2 years ago range-field-render.php 2 years ago repeater-field-render.php 2 years ago select-field-render.php 2 years ago text-field-render.php 2 years ago textarea-field-render.php 2 years ago time-field-render.php 2 years ago wysiwyg-field-render.php 2 years ago
form-builder.php
246 lines
1 <?php
2
3 namespace Jet_Form_Builder\Blocks\Render;
4
5 use Jet_Form_Builder\Blocks\Block_Helper;
6 use Jet_Form_Builder\Blocks\Dynamic_Value;
7 use Jet_Form_Builder\Blocks\Module;
8 use Jet_Form_Builder\Blocks\Validation;
9 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
10 use Jet_Form_Builder\Classes\Attributes_Trait;
11 use Jet_Form_Builder\Classes\Builder_Helper;
12 use Jet_Form_Builder\Classes\Compatibility;
13 use Jet_Form_Builder\Classes\Get_Template_Trait;
14 use Jet_Form_Builder\Classes\Http\Http_Tools;
15 use Jet_Form_Builder\Classes\Tools;
16 use Jet_Form_Builder\Live_Form;
17 use Jet_Form_Builder\Plugin;
18 use JET_SM\Gutenberg\Style_Manager;
19
20 // If this file is called directly, abort.
21
22 if ( ! defined( 'WPINC' ) ) {
23 die;
24 }
25
26 /**
27 * Form builder class
28 */
29 class Form_Builder {
30
31 use Attributes_Trait;
32 use Get_Template_Trait;
33
34 public $form_id;
35 public $post;
36 public $args = array();
37
38 private $form_content;
39
40 /**
41 * Constructor for the class
42 *
43 * @param null $form_id
44 * @param array $args
45 */
46 public function __construct( $form_id = null, $args = array() ) {
47
48 if ( ! $form_id ) {
49 return;
50 }
51 $this->form_id = $form_id;
52 $this->set_form_args( $args );
53 }
54
55 /**
56 * Render from HTML
57 *
58 * @return false|string [type] [description]
59 */
60 public function render_form() {
61
62 if ( $this->pre_render() ) {
63 return '';
64 }
65
66 if ( ! jet_fb_preset( $this->form_id )->general()->sanitize_source() ) {
67 echo 'You are not permitted to submit this form!';
68
69 return '';
70 }
71
72 $blocks = Live_Form::instance()
73 ->set_form_id( $this->form_id )
74 ->set_specific_data_for_render( $this->args )
75 ->setup_fields();
76
77 $form = $this->start_form();
78
79 $form .= Form_Hidden_Fields::render();
80
81 $form .= jet_fb_live()->maybe_progress_pages();
82 $form .= jet_fb_live()->maybe_start_page( true );
83
84 foreach ( $blocks as $block ) {
85 $form .= render_block( $block );
86 }
87
88 $form .= jet_fb_live()->maybe_end_page( true );
89 $form .= $this->end_form();
90
91 return $form;
92 }
93
94
95 /**
96 * @param $arguments
97 *
98 * @return Form_Builder
99 */
100 public function set_form_args( $arguments ): Form_Builder {
101 $this->args = array_intersect_key( $arguments, Form_Arguments::arguments() );
102
103 $this->args['className'] = $arguments['className'] ?? '';
104 $this->args['anchor'] = $arguments['anchor'] ?? '';
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 $base_classes = sprintf(
131 'jet-form-builder layout-%1$s submit-type-%2$s',
132 jet_fb_live_args()->fields_layout,
133 jet_fb_live_args()->submit_type
134 );
135
136 /**
137 * We use form builder methods to add attributes, as the form can be displayed
138 * not only with the Gutenberg block, but also with a third-party builder widget
139 */
140 $this->add_attribute( 'id', $this->args['anchor'] );
141 $this->add_attribute( 'class', $base_classes );
142 $this->add_attribute( 'action', Http_Tools::get_form_action_url() );
143 $this->add_attribute( 'method', \WP_REST_Server::CREATABLE );
144 $this->add_attribute( 'data-form-id', $this->form_id );
145 $this->add_attribute( 'data-layout', jet_fb_live_args()->fields_layout );
146 $this->add_attribute( 'enctype', 'multipart/form-data' );
147 $this->add_attribute( 'data-validation-type', jet_fb_live_args()->validation_type );
148 $this->add_attribute( 'data-clear', jet_fb_live_args()->clear );
149 $this->add_attribute( 'novalidate' );
150
151 /**
152 * Backward compatibility.
153 * We leave only the basic ones in the classes, because the value
154 * from className is added "from above"
155 *
156 * Without it, custom classes will be on the <form> tag and the outer <div>
157 */
158 $this->add_attribute(
159 'class',
160 Compatibility::has_jet_sm() ? '' : $this->args['className']
161 );
162
163 $start_form .= sprintf(
164 '<form %1$s>',
165 $this->get_attributes_string()
166 );
167
168 $start_form .= apply_filters( 'jet-form-builder/after-start-form', '', $this );
169
170 return $start_form;
171 }
172
173 public function end_form() {
174 /** @var Module $blocks */
175 /** @noinspection PhpUnhandledExceptionInspection */
176 $blocks = jet_form_builder()->module( 'blocks' );
177
178 $blocks->enqueue_frontend_assets();
179
180 $end_form = apply_filters( 'jet-form-builder/before-end-form', '', $this );
181 $form_id = $this->form_id;
182
183 ob_start();
184
185 include $this->get_global_template( 'common/end-form.php' );
186
187 $end_form .= ob_get_clean();
188
189 $end_form .= apply_filters( 'jet-form-builder/after-end-form', '', $this );
190
191 return $end_form;
192 }
193
194 private function render_styles(): string {
195 if ( wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
196 return $this->get_inline_styles();
197 }
198
199 if ( Tools::is_elementor_editor() ) {
200 return $this->get_inline_styles();
201 }
202
203 Builder_Helper::enqueue_global_styles();
204 Builder_Helper::enqueue_style_form( $this->form_id );
205
206 return '';
207 }
208
209 private function get_inline_styles(): string {
210 return sprintf(
211 '<style id="jet-form-builder-%s-inline-css">%s</style>',
212 $this->form_id,
213 Plugin::instance()->post_type->maybe_get_jet_sm_ready_styles( $this->form_id )
214 );
215 }
216
217
218 private function maybe_render_fonts_block(): string {
219 if (
220 ! Compatibility::has_jet_sm()
221 || ! method_exists( Style_Manager::get_instance(), 'get_blocks_fonts' )
222 ) {
223 return '';
224 }
225 $fonts = Style_Manager::get_instance()->get_blocks_fonts( $this->form_id );
226
227 if ( ! $fonts ) {
228 return '';
229 }
230
231 $fonts = trim( $fonts, '"' );
232 $fonts = wp_unslash( $fonts );
233
234 return wp_kses(
235 $fonts,
236 array(
237 'link' => array(
238 'href' => true,
239 'rel' => true,
240 ),
241 )
242 );
243 }
244
245 }
246