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