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