PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.8
JetFormBuilder — Dynamic Blocks Form Builder v3.0.8
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 3 years ago addons 3 years ago admin 3 years ago blocks 3 years ago classes 3 years ago compatibility 3 years ago db-queries 3 years ago dev-mode 3 years ago exceptions 3 years ago form-actions 3 years ago form-messages 3 years ago form-patterns 3 years ago form-response 3 years ago gateways 3 years ago generators 3 years ago integrations 3 years ago migrations 3 years ago post-meta 3 years ago presets 3 years ago request 3 years ago rest-api 3 years ago shortcodes 3 years ago wp-cli 3 years ago autoloader.php 3 years ago file-upload.php 3 years ago form-break.php 3 years ago form-handler.php 3 years ago form-manager.php 3 years ago live-form.php 3 years ago plugin.php 3 years ago post-type.php 3 years ago
live-form.php
189 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 use Jet_Form_Builder\Classes\Post\Post_Tools;
12
13 // If this file is called directly, abort.
14 if ( ! defined( 'WPINC' ) ) {
15 die;
16 }
17
18
19 /**
20 * @method static Live_Form instance()
21 *
22 * Class Live_Form
23 * @package Jet_Form_Builder
24 */
25 class Live_Form {
26
27 use Attributes_Trait;
28 use Get_Template_Trait;
29 use Instance_Trait;
30
31 /**
32 * @var bool|int
33 */
34 public $form_id = false;
35 /** @var Form_Arguments */
36 public $spec_data;
37 public $post;
38 public $_conditional_blocks = array();
39 public $_repeaters = array();
40 public $blocks = array();
41
42 // for progress
43 public $form_break;
44 public $field_names = array();
45
46 /**
47 * Create form instance
48 *
49 * @param [type] $form_id [description]
50 */
51 private function __construct() {
52 $this->post = $this->current_post();
53 $this->spec_data = new Form_Arguments();
54 }
55
56 public function set_form_id( $form_id ) {
57 $this->form_id = $form_id;
58
59 return $this;
60 }
61
62 /**
63 * @param array $incoming_attributes
64 *
65 * @return $this
66 */
67 public function set_specific_data_for_render( $incoming_attributes = array() ) {
68 $this->spec_data
69 ->set_form_id( $this->form_id )
70 ->load( $incoming_attributes );
71
72 return $this;
73 }
74
75 /**
76 * Setup fields prop
77 *
78 * @return array[]
79 */
80 public function setup_fields(): array {
81 $this->blocks = $this->get_form_break()->set_pages(
82 Block_Helper::get_blocks_by_post( $this->form_id )
83 );
84
85 jet_form_builder()->regexp->set_field_names(
86 Block_Helper::get_form_field_names( $this->blocks )
87 );
88
89 return $this->blocks;
90 }
91
92 public function maybe_progress_pages() {
93 if ( ! $this->spec_data->enable_progress || 0 === $this->get_form_break()->get_pages() ) {
94 return '';
95 }
96
97 return $this->get_form_break()->render_progress(
98 'default',
99 array(
100 'jet-form-builder-progress-pages--global',
101 )
102 );
103 }
104
105
106 public static function force_render_field( $name, $arguments = array() ) {
107 if ( empty( $name ) ) {
108 return '';
109 }
110 $field = jet_form_builder()->blocks->get_field_by_name( $name );
111
112 if ( ! $field instanceof Block_Type_Base ) {
113 return '';
114 }
115 $arguments['_static_value'] = true;
116
117 $field->set_block_data( $arguments );
118
119 return $field->get_block_renderer();
120 }
121
122
123 /**
124 * Maybe start new page
125 *
126 * @param bool $force_first
127 *
128 * @return false|string|void
129 */
130 public function maybe_start_page( $force_first = false ) {
131 return $this->get_form_break()->maybe_start_page( $force_first );
132 }
133
134 /**
135 * Maybe start new page
136 *
137 * @param $is_last
138 * @param $field
139 *
140 * @return false|string|void [type] [description]
141 */
142 public function maybe_end_page( $is_last = false, $field = false ) {
143 return $this->get_form_break()->maybe_end_page( $is_last, $field );
144 }
145
146 /**
147 * @param string $name
148 *
149 * @return Form_Break
150 */
151 public function get_form_break( $name = '' ) {
152 if ( ! $name && ! $this->form_break ) {
153 $this->form_break = new Form_Break();
154 }
155 if ( $name && ! $this->isset_form_break( $name ) ) {
156 $this->_conditional_blocks[ $name ] = array( 'break' => new Form_Break() );
157 }
158
159 return $name ? $this->_conditional_blocks[ $name ]['break'] : $this->form_break;
160 }
161
162 public function isset_form_break( $name ) {
163 return isset( $this->_conditional_blocks[ $name ] );
164 }
165
166 public function get_repeater( $name ) {
167 return $this->_repeaters[ $name ] ?? array();
168 }
169
170 public function set_repeater( $name, $attrs ) {
171 $this->_repeaters[ $name ] = array_merge( $this->get_repeater( $name ), $attrs );
172 }
173
174 private function current_post() {
175 global $post;
176
177 if ( wp_doing_ajax() && empty( $post->ID ) ) {
178 $url = wp_get_referer();
179 $post_id = url_to_postid( $url );
180
181 return get_post( $post_id );
182 } else {
183 return $post;
184 }
185 }
186
187
188 }
189