bookmark_bordergform_user_registration_prepared_value

Description

This filter can be used to modify a field value before it is saved to the user meta.

Usage

add_filter( 'gform_user_registration_prepared_value', 'your_function_name', 10, 5 );

Parameters

  • $value string

    The value to be modified.

  • $field Field Object

    The field currently being processed.

  • $input_id string

    The ID of the field input currently being processed.

  • $entry Entry Object

    The entry currently being processed.

  • $is_username bool

    Indicates if the current field is mapped to the username.

Examples

Country Code

The following example shows how you can replace the address field country value with the country code.

add_filter( 'gform_user_registration_prepared_value', function ( $value, $field, $input_id, $entry, $is_username ) {
    $country_id = $field->id . '.6';
    if ( $field->type == 'address' && $input_id == $country_id ) {
        return GF_Fields::get( 'address' )->get_country_code( $value );
    }
    return $value;
}, 10, 5 );

Checkboxes as serialized data

The following example shows how to serialize values of a checkboxes field before saving to the user meta for a field with id 18.

add_filter( 'gform_user_registration_prepared_value', 'gf_serialize_checkboxes', 10, 5 );

function gf_serialize_checkboxes( $value, $field, $input_id, $entry, $is_username ) {

    if ( $field->id == '18' && $field->type == 'checkbox' ) { // Update 18 to your field id number
		// Get a comma separated list of checkboxes checked
		$checked = is_object( $field ) ? $field->get_value_export( $entry ) : '';

		// Convert to array
		$values = explode(",", $checked);

		// Serialize the data
		$value = maybe_serialize( $values );
    }
    return $value;
}

Placement

Your code snippet should be placed in the functions.php file of your active theme

Since

This filter was added in version 2.1

Source Code

$value = apply_filters( 'gform_user_registration_prepared_value', $value, $field, $input_id, $entry, $is_username );

This filter is located in GF_User_Registration::get_prepared_value() in class-gf-user-registration.php