spivurno
12/21/2014 - 5:39 PM

Gravity Wiz // Gravity Forms // Capitalize Submitted Data

Gravity Wiz // Gravity Forms // Capitalize Submitted Data

<?php
/**
 * Gravity Wiz // Gravity Forms // Capitalize Submitted Data
 *
 * Capitializes all words in Single Line Text, Paragraph Text, Address and Name fields.
 *
 */
add_action( 'gform_pre_submission', 'gw_capitalize_submitted_data' );
function gw_capitalize_submitted_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'] ) );
				$_POST[ $input_key ] = ucwords( rgpost( $input_key ) );
			}
		} else {
			$input_key = sprintf( 'input_%s', $field['id'] );
			$_POST[ $input_key ] = ucwords( rgpost( $input_key ) );
		}

	}

	return $form;
}