PluginProbe
Advanced Forms for ACF / trunk
Advanced Forms for ACF vtrunk
1.9.0 1.9.1 1.9.2.1 1.9.3 1.9.3.1 1.9.3.2 1.9.3.3 1.9.3.4 1.9.3.5 1.9.3.6 1.9.3.7 1.9.3.8 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.3.1 1.0.3.2 1.0.3.3 1.0.4 1.1.0 1.1.1 1.2.0 1.3.0 All 51 releases
advanced-forms / api / api-submissions.php

api-submissions.php in Advanced Forms for ACF trunk, at api/api-submissions.php

82 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 /**
5 * Returns true if a successful submission was performed
6 *
7 * @since 1.1
8 */
9 function af_has_submission( $hash = false ) {
10 $submission = AF()->submission;
11
12 if ( is_null( $submission ) ) {
13 return false;
14 }
15
16 if ( $hash && $hash != af_form_instance_hash( $submission['form']['key'], $submission['args'] ) ) {
17 return false;
18 }
19
20 return true;
21 }
22
23
24 function af_submission_failed( $key = false ) {
25 $submission = AF()->submission;
26
27 if ( is_null( $submission ) ) {
28 return false;
29 }
30
31 if ( $key && $key != $submission['form']['key'] ) {
32 return false;
33 }
34
35 if ( isset( $submission['errors'] ) && ! empty( $submission['errors'] ) ) {
36 return true;
37 }
38
39 return false;
40 }
41
42
43 /**
44 * Adds a general error for a form submission.
45 * Used during the before_submission hook to stop submission.
46 */
47 function af_add_submission_error( $message ) {
48 AF()->submission['errors'][] = $message;
49 }
50
51
52 /**
53 * Adds an error for a specific field.
54 * Used as an alternative for acf_add_validation_error with support for field names/keys.
55 *
56 * @since 1.5.0
57 *
58 */
59 function af_add_error( $field_key_or_name, $message ) {
60 $field = af_get_field_object( $field_key_or_name );
61
62 if ( $field ) {
63 $input_name = sprintf( '%s[%s]', $field['prefix'], $field['key'] );
64 acf_add_validation_error( $input_name, $message );
65 }
66 }
67
68
69 /**
70 * Calculates a unique hash for a form instance, based on the form key and arguments.
71 *
72 * @since 1.6.3
73 *
74 */
75 function af_form_instance_hash( $form_key, $args ) {
76 $args['form'] = $form_key;
77
78 // Sort args to make the hash order-independent
79 ksort( $args );
80
81 return md5( json_encode( $args ) );
82 }