Last active
May 2, 2023 18:11
-
-
Save matty0501/5d600450e8c939faa926e692b2572d91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Modified version of this snippet: https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-capitilize-submitted-data.php | |
* | |
* Capitializes all words in Single Line Text, Paragraph Text, Address and Name fields - only when the value is all UPPERCASE or all lowercase | |
*/ | |
// Update "123" to the ID of the Form | |
add_action( 'gform_pre_submission_123', 'gw_capitalize_uppercase_lowercase_data' ); | |
function gw_capitalize_uppercase_lowercase_data( $form ) { | |
$applicable_input_types = array( 'address', 'text', 'textarea', 'name' ); | |
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'] ) ); | |
if( strtolower( rgpost( $input_key ) ) == $_POST[ $input_key ] || strtoupper( rgpost( $input_key ) ) == $_POST[ $input_key ] ){ | |
$_POST[ $input_key ] = ucwords( strtolower( rgpost( $input_key ) ) ); | |
} | |
} | |
} else { | |
$input_key = sprintf( 'input_%s', $field['id'] ); | |
if( strtolower( rgpost( $input_key ) ) == $_POST[ $input_key ] || strtoupper( rgpost( $input_key ) ) == $_POST[ $input_key ] ){ | |
$_POST[ $input_key ] = ucwords( strtolower( rgpost( $input_key ) ) ); | |
} | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment