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