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