-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathgw-capitilize-submitted-data.php
42 lines (36 loc) · 1.3 KB
/
gw-capitilize-submitted-data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Gravity Wiz // Gravity Forms // Capitalize Submitted Data
* https://gravitywiz.com/
*
* Instruction Video: https://www.loom.com/share/dff6d63f5a9c44938fdc0506ce5d4965
*
* Capitializes all words in Single Line Text, Paragraph Text, Address and Name fields.
*/
// Update "123" to the ID of the Form
add_action( 'gform_pre_submission_123', 'gw_capitalize_submitted_data' );
function gw_capitalize_submitted_data( $form ) {
$applicable_input_types = array( 'address', 'text', 'textarea', 'name', 'list' );
foreach ( $form['fields'] as $field ) {
$input_type = GFFormsModel::get_input_type( $field );
if ( ! in_array( $input_type, $applicable_input_types ) ) {
continue;
}
if ( isset( $field['inputs'] ) && is_array( $field['inputs'] ) ) {
foreach ( $field['inputs'] as $input ) {
$input_key = sprintf( 'input_%s', str_replace( '.', '_', $input['id'] ) );
$_POST[ $input_key ] = ucwords( strtolower( rgpost( $input_key ) ) );
}
} else {
$input_key = sprintf( 'input_%s', $field['id'] );
if ( $field->type == 'list' ) {
$_POST[ $input_key ] = array_map( function( $value ) {
return ucwords( strtolower( $value ) );
}, $_POST[ $input_key ] );
} else {
$_POST[ $input_key ] = ucwords( strtolower( rgpost( $input_key ) ) );
}
}
}
return $form;
}