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