PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.9.2
Pods – Custom Content Types and Fields v3.3.9.2
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / ui / front / form.php
pods / ui / front Last commit date
display 3 days ago pagination 3 days ago filters.php 3 days ago form.php 3 days ago view.php 3 days ago widgets.php 3 days ago
form.php
220 lines
1 <?php
2
3 // Don't load directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 die( '-1' );
6 }
7
8 // phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
9
10 /**
11 * @var array $fields
12 * @var boolean $fields_only
13 * @var Pods $pod
14 * @var array $params
15 * @var string $label
16 * @var string $thank_you
17 * @var string $output_type
18 * @var string|null $form_key
19 */
20
21 pods_form_enqueue_style( 'pods-form' );
22 pods_form_enqueue_script( 'pods' );
23
24 $pod_name = $pod->pod;
25 $id = $pod->id();
26
27 // Set up fields.
28 foreach ( $fields as $k => $field ) {
29 // Make sure all required array keys exist.
30 if ( ! $field instanceof \Pods\Whatsit\Field ) {
31 $field = wp_parse_args( $field, [
32 'name' => '',
33 'type' => '',
34 'label' => '',
35 'help' => '',
36 ] );
37
38 $fields[ $k ] = $field;
39 }
40
41 if ( in_array( $field['name'], [ 'created', 'modified' ], true ) ) {
42 unset( $fields[ $k ] );
43 } elseif ( ! pods_permission( $field ) ) {
44 if ( pods_v( 'hidden', $field, false ) ) {
45 $fields[ $k ] = pods_form_field_make_hidden( $fields[ $k ] );
46 } elseif ( pods_v_bool( 'read_only_restricted', $field ) ) {
47 $fields[ $k ] = pods_form_field_make_readonly( $fields[ $k ] );
48 } else {
49 unset( $fields[ $k ] );
50
51 continue;
52 }
53 } elseif ( ! pods_has_permissions( $field ) ) {
54 if ( pods_v_bool( 'hidden', $field ) ) {
55 $fields[ $k ] = pods_form_field_make_hidden( $fields[ $k ] );
56 } elseif ( pods_v_bool( 'read_only', $field ) ) {
57 $fields[ $k ] = pods_form_field_make_readonly( $fields[ $k ] );
58 }
59 }
60 }
61
62 $submittable_fields = $fields;
63
64 foreach ( $submittable_fields as $k => $field ) {
65 if ( ! pods_v( 'readonly', $field, false ) ) {
66 continue;
67 }
68
69 unset( $submittable_fields[ $k ] );
70 }
71
72 $uri_hash = pods_access_form_uri_hash();
73
74 if ( pods_access_form_nonce_present_in_request( 'form' ) ) {
75 try {
76 $id = $pod->api->process_form( $_POST, $pod, $submittable_fields, $thank_you );
77 } catch ( Exception $e ) {
78 pods_message( esc_html( $e->getMessage() ), 'error' );
79 }
80 }
81
82 $field_prefix = '';
83
84 $counter = (int) pods_static_cache_get( $pod->pod . '-counter', 'pods-forms' );
85
86 // Shift counter by 1 so that it always starts at 1.
87 $counter ++;
88
89 // Enforce the counter.
90 PodsForm::$form_counter = $counter;
91
92 pods_static_cache_set( $pod->pod . '-counter', $counter, 'pods-forms' );
93 ?>
94
95 <?php if ( ! $fields_only ) : ?>
96 <?php $field_prefix = 'pods_field_'; ?>
97 <form
98 action=""
99 method="post"
100 class="pods-submittable pods-form pods-form-front pods-form-pod-<?php echo esc_attr( $pod_name ); ?> pods-submittable-ajax"
101 data-location="<?php echo esc_attr( pods_enforce_safe_url( $thank_you ) ); ?>"
102 id="pods-form-<?php echo esc_attr( $pod_name . '-' . $counter ); ?>"
103 data-pods-pod-name="<?php echo esc_attr( $pod_name ); ?>"
104 data-pods-item-id="<?php echo esc_attr( $id ); ?>"
105 data-pods-form-counter="<?php echo esc_attr( $counter ); ?>"
106 >
107 <div class="pods-submittable-fields">
108 <?php PodsForm::output_field( 'action', 'pods_admin', 'hidden' ); ?>
109 <?php PodsForm::output_field( 'method', 'process_form', 'hidden' ); ?>
110 <?php PodsForm::output_field( 'do', ( ! empty( $id ) ? 'save' : 'create' ), 'hidden' ); ?>
111 <?php pods_access_output_form_nonce_fields( $pod_name, $id, $submittable_fields, pods_access_form_field_names( 'form' ), $uri_hash ); ?>
112 <?php PodsForm::output_field( '_pods_form_key', ! empty( $form_key ) ? $form_key : '', 'hidden' ); ?>
113 <?php PodsForm::output_field( '_pods_location', $_SERVER['REQUEST_URI'], 'hidden' ); ?>
114 <?php endif; ?>
115
116 <?php
117 /**
118 * Runs before fields are outputted.
119 *
120 * @params array $fields Fields of the form.
121 * @params object $pod The current Pod object.
122 * @params array $params The form's parameters.
123 *
124 * @since 2.3.19
125 */
126 do_action( 'pods_form_pre_fields', $fields, $pod, $params );
127
128 $field_row_classes = 'pods-field-html-class';
129 $heading_tag = 'h3';
130
131 $pre_callback = static function ( $field_name, $id, $field, $pod ) use ( $fields, $params ) {
132 /**
133 * Runs before a field is output.
134 *
135 * @since 2.3.19
136 *
137 * @param array $field The current field.
138 * @param array $fields All fields of the form.
139 * @param object $pod The current Pod object.
140 * @param array $params The form's parameters.
141 */
142 do_action( 'pods_form_pre_field', $field, $fields, $pod, $params );
143 };
144
145 $post_callback = static function ( $field_name, $id, $field, $pod ) use ( $fields, $params ) {
146 /**
147 * Runs after a field is output.
148 *
149 * @since 2.3.19
150 *
151 * @params array $field The current field.
152 * @params array $fields All fields of the form.
153 * @params object $pod The current Pod object.
154 * @params array $params The form's parameters.
155 */
156 do_action( 'pods_form_after_field', $field, $fields, $pod, $params );
157 };
158
159 $template = 'ui/forms/list-rows.php';
160 $template_before = '<div class="pods-form-fieldset">';
161 $template_after = '</div>';
162
163 if ( 'div' === $output_type ) {
164 $template = 'ui/forms/div-rows.php';
165 } elseif ( 'p' === $output_type ) {
166 $template = 'ui/forms/p-rows.php';
167 } elseif ( 'table' === $output_type ) {
168 $template = 'ui/forms/table-rows.php';
169 $template_before = '<table class="pods-form-fieldset">';
170 $template_after = '</table>';
171 }
172
173 echo wp_kses_post( $template_before );
174
175 pods_view( PODS_DIR . $template, compact( array_keys( get_defined_vars() ) ) );
176
177 echo wp_kses_post( $template_after );
178
179 /**
180 * Runs after all fields are outputted.
181 *
182 * @params array $fields Fields of the form
183 * @params object $pod The current Pod object
184 * @params array $params The form's parameters.
185 *
186 * @since 2.3.19
187 */
188 do_action( 'pods_form_after_fields', $fields, $pod, $params );
189 ?>
190
191 <?php if ( ! $fields_only ) : ?>
192 <p class="pods-submit">
193 <img class="waiting" src="<?php echo esc_url( admin_url( '/images/wpspin_light.gif' ) ); ?>" alt="<?php esc_attr_e( 'Submitting...', 'pods' ); ?>">
194 <input type="submit" value=" <?php echo esc_attr( $label ); ?> " class="pods-submit-button" />
195
196 <?php do_action( 'pods_form_after_submit', $pod, $fields, $params ); ?>
197 </p>
198 </div>
199 </form>
200
201 <script type="text/javascript">
202 if ( 'undefined' === typeof pods_form_init ) {
203 var pods_form_init = true;
204
205 document.addEventListener( "DOMContentLoaded", function () {
206 if ( 'undefined' !== typeof jQuery( document ).Pods ) {
207
208 if ( 'undefined' === typeof ajaxurl ) {
209 window.ajaxurl = <?php echo json_encode( esc_url_raw( admin_url( 'admin-ajax.php' ) ) ); ?>;
210 }
211
212 jQuery( document ).Pods( 'validate' );
213 jQuery( document ).Pods( 'submit' );
214 jQuery( document ).Pods( 'dependency', true ); // Pass `true` to trigger init.
215 }
216 }, false );
217 }
218 </script>
219 <?php endif; ?>
220