PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.3
JetFormBuilder — Dynamic Blocks Form Builder v3.0.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 / 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
184 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
45 /**
46 * Create form instance
47 *
48 * @param [type] $form_id [description]
49 */
50 private function __construct() {
51 $this->post = $this->current_post();
52 $this->spec_data = new Form_Arguments();
53 }
54
55 public function set_form_id( $form_id ) {
56 $this->form_id = $form_id;
57
58 return $this;
59 }
60
61 /**
62 * @param array $incoming_attributes
63 *
64 * @return $this
65 */
66 public function set_specific_data_for_render( $incoming_attributes = array() ) {
67 $this->spec_data
68 ->set_form_id( $this->form_id )
69 ->load( $incoming_attributes );
70
71 return $this;
72 }
73
74 /**
75 * Setup fields prop
76 *
77 * @return array[]
78 */
79 public function setup_fields(): array {
80 $this->blocks = $this->get_form_break()->set_pages(
81 Block_Helper::get_blocks_by_post( $this->form_id )
82 );
83
84 return $this->blocks;
85 }
86
87 public function maybe_progress_pages() {
88 if ( ! $this->spec_data->enable_progress || 0 === $this->get_form_break()->get_pages() ) {
89 return '';
90 }
91
92 return $this->get_form_break()->render_progress(
93 'default',
94 array(
95 'jet-form-builder-progress-pages--global',
96 )
97 );
98 }
99
100
101 public static function force_render_field( $name, $arguments = array() ) {
102 if ( empty( $name ) ) {
103 return '';
104 }
105 $field = jet_form_builder()->blocks->get_field_by_name( $name );
106
107 if ( ! $field instanceof Block_Type_Base ) {
108 return '';
109 }
110 $arguments['_static_value'] = true;
111
112 $field->set_block_data( $arguments );
113
114 return $field->get_block_renderer();
115 }
116
117
118 /**
119 * Maybe start new page
120 *
121 * @param bool $force_first
122 *
123 * @return false|string|void
124 */
125 public function maybe_start_page( $force_first = false ) {
126 return $this->get_form_break()->maybe_start_page( $force_first );
127 }
128
129 /**
130 * Maybe start new page
131 *
132 * @param $is_last
133 * @param $field
134 *
135 * @return false|string|void [type] [description]
136 */
137 public function maybe_end_page( $is_last = false, $field = false ) {
138 return $this->get_form_break()->maybe_end_page( $is_last, $field );
139 }
140
141 /**
142 * @param string $name
143 *
144 * @return Form_Break
145 */
146 public function get_form_break( $name = '' ) {
147 if ( ! $name && ! $this->form_break ) {
148 $this->form_break = new Form_Break();
149 }
150 if ( $name && ! $this->isset_form_break( $name ) ) {
151 $this->_conditional_blocks[ $name ] = array( 'break' => new Form_Break() );
152 }
153
154 return $name ? $this->_conditional_blocks[ $name ]['break'] : $this->form_break;
155 }
156
157 public function isset_form_break( $name ) {
158 return isset( $this->_conditional_blocks[ $name ] );
159 }
160
161 public function get_repeater( $name ) {
162 return $this->_repeaters[ $name ] ?? array();
163 }
164
165 public function set_repeater( $name, $attrs ) {
166 $this->_repeaters[ $name ] = array_merge( $this->get_repeater( $name ), $attrs );
167 }
168
169 private function current_post() {
170 global $post;
171
172 if ( wp_doing_ajax() && empty( $post->ID ) ) {
173 $url = wp_get_referer();
174 $post_id = url_to_postid( $url );
175
176 return get_post( $post_id );
177 } else {
178 return $post;
179 }
180 }
181
182
183 }
184