PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
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 / live-form.php
jetformbuilder / includes Last commit date
actions 1 month ago addons 11 months ago admin 3 weeks ago blocks 6 days ago classes 2 weeks ago db-queries 2 weeks ago exceptions 2 years ago form-messages 1 year ago form-patterns 2 years ago form-response 2 years ago generators 1 day ago migrations 1 month ago presets 6 days ago request 2 years ago autoloader.php 1 year ago file-upload.php 2 years ago form-break.php 2 years ago form-handler.php 1 week ago form-manager.php 2 months ago functions.php 2 years ago live-form.php 1 week ago plugin.php 2 years ago
live-form.php
222 lines
1 <?php
2
3 namespace Jet_Form_Builder;
4
5 use Jet_Form_Builder\Blocks\Block_Helper;
6 use Jet_Form_Builder\Blocks\Types\Base as Block_Type_Base;
7 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
8 use Jet_Form_Builder\Classes\Attributes_Trait;
9 use Jet_Form_Builder\Classes\Get_Template_Trait;
10 use Jet_Form_Builder\Classes\Instance_Trait;
11
12 // If this file is called directly, abort.
13 if ( ! defined( 'WPINC' ) ) {
14 die;
15 }
16
17 /**
18 * @method static Live_Form instance()
19 *
20 * Class Live_Form
21 * @package Jet_Form_Builder
22 */
23 class Live_Form {
24
25 use Attributes_Trait;
26 use Get_Template_Trait;
27 use Instance_Trait;
28
29 /**
30 * @var bool|int
31 */
32 public $form_id = false;
33 /** @var Form_Arguments */
34 public $spec_data;
35 // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
36 public $_conditional_blocks = array();
37 public $blocks = array();
38 // phpcs:enable PSR2.Classes.PropertyDeclaration.Underscore
39
40 /**
41 * @var Form_Break
42 */
43 public $form_break;
44 public $field_names = array();
45
46 private $ajax_post_id;
47
48 /**
49 * Create form instance
50 *
51 * @param [type] $form_id [description]
52 */
53 private function __construct() {
54 $this->spec_data = new Form_Arguments();
55
56 add_filter(
57 'jet-form-builder/setup-blocks',
58 array( $this, 'remove_extra_page_breaks' )
59 );
60 add_filter(
61 'jet-form-builder/after-end-form',
62 array( self::class, 'on_end_render_form' )
63 );
64 }
65
66 public static function on_end_render_form( string $content ): string {
67 self::clear();
68
69 return $content;
70 }
71
72 public static function clear() {
73 remove_filter(
74 'jet-form-builder/setup-blocks',
75 array( self::$instance, 'remove_extra_page_breaks' )
76 );
77 remove_filter(
78 'jet-form-builder/after-end-form',
79 array( self::class, 'on_end_render_form' )
80 );
81
82 self::$instance = null;
83 }
84
85 public function set_form_id( $form_id ) {
86 $this->form_id = $form_id;
87
88 return $this;
89 }
90
91 /**
92 * @param array $incoming_attributes
93 *
94 * @return $this
95 */
96 public function set_specific_data_for_render( $incoming_attributes = array() ) {
97 $this->spec_data
98 ->set_form_id( $this->form_id )
99 ->load( $incoming_attributes );
100
101 return $this;
102 }
103
104 /**
105 * Setup fields prop
106 *
107 * @return array[]
108 */
109 public function setup_fields(): array {
110 $this->blocks = apply_filters(
111 'jet-form-builder/setup-blocks',
112 Block_Helper::get_blocks_by_post( $this->form_id, true, true )
113 );
114
115 jet_form_builder()->regexp->set_field_names(
116 Block_Helper::get_form_field_names( $this->blocks )
117 );
118
119 return $this->blocks;
120 }
121
122 public function remove_extra_page_breaks( array $blocks ) {
123 return $this->get_form_break()->set_pages( $blocks );
124 }
125
126 public function maybe_progress_pages() {
127 if ( ! $this->spec_data->enable_progress || 0 === $this->get_form_break()->get_pages() ) {
128 return '';
129 }
130
131 return $this->get_form_break()->render_progress(
132 'default',
133 array(
134 'jet-form-builder-progress-pages--global',
135 )
136 );
137 }
138
139
140 public static function force_render_field( $name, $arguments = array() ) {
141 if ( empty( $name ) ) {
142 return '';
143 }
144 $field = jet_form_builder()->blocks->get_field_by_name( $name );
145
146 if ( ! $field instanceof Block_Type_Base ) {
147 return '';
148 }
149 $arguments['_static_value'] = true;
150
151 $field->set_block_data( $arguments );
152
153 return $field->get_block_renderer();
154 }
155
156
157 /**
158 * Maybe start new page
159 *
160 * @param bool $force_first
161 *
162 * @return false|string|void
163 */
164 public function maybe_start_page( $force_first = false ) {
165 return $this->get_form_break()->maybe_start_page( $force_first );
166 }
167
168 /**
169 * Maybe start new page
170 *
171 * @param $is_last
172 * @param $field
173 *
174 * @return false|string|void [type] [description]
175 */
176 public function maybe_end_page( $is_last = false, $field = false ) {
177 return $this->get_form_break()->maybe_end_page( $is_last, $field );
178 }
179
180 /**
181 * @param string $name
182 *
183 * @return Form_Break
184 */
185 public function get_form_break( $name = '' ) {
186 if ( ! $name && ! $this->form_break ) {
187 $this->form_break = new Form_Break();
188 }
189 if ( $name && ! $this->isset_form_break( $name ) ) {
190 $this->_conditional_blocks[ $name ] = array( 'break' => new Form_Break() );
191 }
192
193 return $name ? $this->_conditional_blocks[ $name ]['break'] : $this->form_break;
194 }
195
196 public function isset_form_break( $name ) {
197 return isset( $this->_conditional_blocks[ $name ] );
198 }
199
200 public function __get( string $name ) {
201 switch ( $name ) {
202 case 'post':
203 return $this->current_post();
204 default:
205 return null;
206 }
207 }
208
209 private function current_post() {
210 global $post;
211
212 if ( wp_doing_ajax() && empty( $post->ID ) && ! $this->ajax_post_id ) {
213 $url = wp_get_referer();
214
215 $this->ajax_post_id = url_to_postid( $url );
216 }
217
218 return $this->ajax_post_id ? get_post( $this->ajax_post_id ) : $post;
219 }
220
221 }
222