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 / forms / form.php
pods / ui / forms Last commit date
type 2 days ago div-row.php 2 days ago div-rows.php 2 days ago form.php 2 days ago list-row.php 2 days ago list-rows.php 2 days ago p-row.php 2 days ago p-rows.php 2 days ago table-row.php 2 days ago table-rows.php 2 days ago
form.php
256 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 string $form_type
12 * @var PodsUI $obj
13 * @var Pods $pod
14 * @var null|string $thank_you
15 * @var null|string $thank_you_alt
16 * @var null|string $label
17 * @var string|null $form_key
18 */
19
20 use Pods\Static_Cache;
21
22 pods_form_enqueue_script( 'pods' );
23 pods_form_enqueue_style( 'pods-form' );
24
25 $is_settings_pod = 'settings' === $pod->pod_data['type'];
26
27 if ( empty( $fields ) || ! is_array( $fields ) ) {
28 $fields = $obj->pod->fields;
29 }
30
31 if ( ! isset( $duplicate ) || $is_settings_pod ) {
32 $duplicate = false;
33 } else {
34 $duplicate = (boolean) $duplicate;
35 }
36
37 $groups = PodsInit::$meta->groups_get( $pod->pod_data['type'], $pod->pod_data['name'], $fields );
38
39 if ( 1 === count( $groups ) ) {
40 $first_group = current( $groups );
41
42 if ( 0 === count( $first_group['fields'] ) ) {
43 $groups = [];
44 }
45 }
46
47 $pod_name = $pod->pod_data['name'];
48 $pod_options = $pod->pod_data['options'];
49 $pod_options = apply_filters( "pods_advanced_content_type_pod_data_{$pod_name}", $pod_options, $pod->pod_data['name'] );
50 $pod_options = apply_filters( 'pods_advanced_content_type_pod_data', $pod_options, $pod->pod_data['name'] );
51
52 $group_fields = array();
53 $submittable_fields = array();
54
55 foreach ( $groups as $g => $group ) {
56 // unset fields
57 foreach ( $group['fields'] as $k => $field ) {
58 if ( in_array( $field['name'], array( 'created', 'modified' ), true ) ) {
59 unset( $group['fields'][ $k ] );
60
61 continue;
62 } elseif ( ! pods_permission( $field ) ) {
63 if ( pods_v_bool( 'hidden', $field['options'] ) ) {
64 $group['fields'][ $k ] = pods_form_field_make_hidden( $group['fields'][ $k ] );
65 } elseif ( pods_v_bool( 'read_only_restricted', $group['fields'][ $k ]['options'] ) ) {
66 $group['fields'][ $k ] = pods_form_field_make_readonly( $group['fields'][ $k ] );
67 } else {
68 unset( $group['fields'][ $k ] );
69
70 continue;
71 }
72 } elseif ( ! pods_has_permissions( $field ) ) {
73 if ( pods_v_bool( 'hidden', $field['options'] ) ) {
74 $group['fields'][ $k ] = pods_form_field_make_hidden( $group['fields'][ $k ] );
75 } elseif ( pods_v_bool( 'read_only', $field['options'] ) ) {
76 $group['fields'][ $k ] = pods_form_field_make_readonly( $group['fields'][ $k ] );
77 }
78 }//end if
79
80 if ( ! pods_v_bool( 'readonly', $field ) ) {
81 $submittable_fields[ $field['name'] ] = $group['fields'][ $k ];
82 }
83
84 $group_fields[ $field['name'] ] = $group['fields'][ $k ];
85 }//end foreach
86 $groups[ $g ] = $group;
87 }//end foreach
88
89 if ( ! isset( $thank_you_alt ) ) {
90 $thank_you_alt = $thank_you;
91 }
92
93 $uri_hash = pods_access_form_uri_hash();
94 $item_id = $duplicate ? 0 : $pod->id();
95
96 $submit_result = null;
97
98 if ( pods_access_form_nonce_present_in_request( 'form' ) ) {
99 try {
100 $params = pods_unslash( (array) $_POST );
101
102 $submit_result = 0 !== $pod->api->process_form( $params, $pod, $submittable_fields, $thank_you );
103 } catch ( Exception $e ) {
104 $obj->error( wp_kses_post( $e->getMessage() ) );
105 }
106 } elseif ( isset( $_GET['do'] ) ) {
107 $submit_result = 0 !== $pod->id();
108 }
109
110 if ( null !== $submit_result ) {
111 $messages = [
112 'success' => __( 'Success', 'pods' ),
113 'error' => __( 'Error', 'pods' ),
114 // translators: %s: The singular item label.
115 'view_item' => __( 'View %s', 'pods' ),
116 // translators: %s: The singular item label.
117 'success_saved' => _x( '%s saved successfully', 'The success message shown after saving form', 'pods' ),
118 // translators: %s: The singular item label.
119 'success_created' => _x( '%s created successfully', 'The success message shown after saving form', 'pods' ),
120 // translators: %s: The singular item label.
121 'success_duplicated' => _x( '%s duplicated successfully', 'The success message shown after saving form', 'pods' ),
122 // translators: %s: The singular item label.
123 'error_saved' => _x( '%s not saved', 'The error message shown after saving form', 'pods' ),
124 // translators: %s: The singular item label.
125 'error_created' => _x( '%s not created', 'The error message shown after saving form', 'pods' ),
126 // translators: %s: The singular item label.
127 'error_duplicated' => _x( '%s not duplicated', 'The error message shown after saving form', 'pods' ),
128 ];
129
130 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_saved'] );
131 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_saved'] );
132
133 if ( ! $is_settings_pod ) {
134 if ( 'create' === pods_v( 'do', 'post', pods_v( 'do', 'get', 'save' ) ) ) {
135 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_created'] );
136 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_created'] );
137 } elseif ( 'duplicate' === pods_v( 'do', 'get', 'save' ) ) {
138 $success_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['success'], $messages['success_duplicated'] );
139 $error_message = sprintf( '<strong>%1$s:</strong> %2$s.', $messages['error'], $messages['error_duplicated'] );
140 }
141 }
142
143 if ( $submit_result ) {
144 $message = sprintf( $success_message, $obj->item );
145
146 if ( ! $is_settings_pod && ! empty( $pod_options['detail_url'] ) ) {
147 $message_view =
148 $message .= sprintf(
149 ' <a target="_blank" rel="noopener noreferrer" href="%1$s">%2$s</a>',
150 esc_url( $pod->field( 'detail_url' ) ),
151 esc_html( sprintf( $messages['view_item'], $obj->item ) )
152 );
153 }
154
155 $obj->message( wp_kses_post( $message ) );
156 } else {
157 $error = sprintf( $error_message, $obj->item );
158
159 $obj->error( wp_kses_post( $error ) );
160 }
161 }
162
163 if ( ! isset( $label ) ) {
164 $label = __( 'Save', 'pods' );
165 }
166
167 $do = 'create';
168
169 if ( 0 < $pod->id() ) {
170 if ( $duplicate ) {
171 $do = 'duplicate';
172 } else {
173 $do = 'save';
174 }
175 }
176
177 $counter = (int) pods_static_cache_get( $pod->pod . '-counter', 'pods-forms' );
178
179 // Shift counter by 1 so that it always starts at 1.
180 $counter ++;
181
182 // Enforce the counter.
183 PodsForm::$form_counter = $counter;
184
185 pods_static_cache_set( $pod->pod . '-counter', $counter, 'pods-forms' );
186 ?>
187
188 <form
189 action=""
190 method="post"
191 class="pods-submittable pods-form pods-form-pod-<?php echo esc_attr( $pod->pod ); ?> pods-submittable-ajax"
192 id="pods-form-<?php echo esc_attr( $pod->pod . '-' . $counter ); ?>"
193 data-pods-pod-name="<?php echo esc_attr( $pod->pod ); ?>"
194 data-pods-item-id="<?php echo esc_attr( $item_id ); ?>"
195 data-pods-form-counter="<?php echo esc_attr( $counter ); ?>"
196 >
197 <div class="pods-submittable-fields">
198 <?php
199 PodsForm::output_field( 'action', 'pods_admin', 'hidden' );
200 PodsForm::output_field( 'method', 'process_form', 'hidden' );
201 PodsForm::output_field( 'do', $do, 'hidden' );
202 pods_access_output_form_nonce_fields( $pod->pod, $item_id, $submittable_fields, pods_access_form_field_names( 'form' ), $uri_hash );
203 PodsForm::output_field( '_pods_form_key', ! empty( $form_key ) ? $form_key : '', 'hidden' );
204 PodsForm::output_field( '_pods_location', $_SERVER['REQUEST_URI'], 'hidden' );
205
206 // Nonce for the non-AJAX/direct-POST save path. With JavaScript the form submits via AJAX to process_form(); without JS it posts directly and is handled by PodsUI::go() -> save().
207 if ( $obj instanceof PodsUI ) {
208 PodsForm::output_field( $obj->num_prefix . '_wpnonce' . $obj->num, wp_create_nonce( 'pods-ui-save' ), 'hidden' );
209 }
210
211 pods_view( PODS_DIR . 'ui/forms/type/' . sanitize_title( $form_type ) . '.php', compact( array_keys( get_defined_vars() ) ) );
212 ?>
213 </div>
214 </form>
215
216 <script type="text/javascript">
217 if ( 'undefined' == typeof ajaxurl ) {
218 var ajaxurl = <?php echo json_encode( esc_url_raw( admin_url( 'admin-ajax.php' ) ) ); ?>;
219 }
220
221 if ( 'undefined' == typeof pods_form_thank_you ) {
222 var pods_form_thank_you = null;
223 }
224
225 <?php if ( $is_settings_pod ) : ?>
226 var pods_admin_submit_callback = function ( id ) {
227 document.location = <?php echo json_encode( esc_url_raw( pods_query_arg( array( 'do' => $do ) ) ) ); ?>;
228 }
229 <?php else : ?>
230 var pods_admin_submit_callback = function ( id ) {
231 id = parseInt( id, 10 );
232 var thank_you = <?php echo json_encode( esc_url_raw( $thank_you ) ); ?>;
233 var thank_you_alt = <?php echo json_encode( esc_url_raw( $thank_you_alt ) ); ?>;
234
235 if ( 'undefined' != typeof pods_form_thank_you && null !== pods_form_thank_you ) {
236 thank_you = pods_form_thank_you;
237 }
238
239 if ( isNaN( id ) ) {
240 document.location = thank_you_alt.replace( 'X_ID_X', String( 0 ) );
241 }
242 else {
243 document.location = thank_you.replace( 'X_ID_X', String( id ) );
244 }
245 }
246 <?php endif; ?>
247
248 jQuery( function ( $ ) {
249 $( document ).Pods( 'validate' );
250 $( document ).Pods( 'submit' );
251 $( document ).Pods( 'dependency', true );
252 $( document ).Pods( 'confirm' );
253 $( document ).Pods( 'exit_confirm' );
254 } );
255 </script>
256