Get selected values from checkboxes and radio buttons via Gravity Forms gform_after_submission hook [closed]

If you have the form/field object you can retrieve a comma separated string containing the fields selected choices by using the GF_Field::get_value_export() method which was added in Gravity Forms 1.9.13.

If you are only going to use it with one or two fields you could do something like this:

$field_id    = 4;
$field       = GFFormsModel::get_field( $form, $field_id );
$field_value = is_object( $field ) ? $field->get_value_export( $entry ) : '';

The above would return the values for the selected choices, if you wanted to return the choice text you would set the third parameter of get_value_export() to true e.g.

$field_value = is_object( $field ) ? $field->get_value_export( $entry, $field_id, true ) : '';

If you need to access all the field values in the entry, but you want the relevant field types formatted to use the choice text then you could do something like this:

add_action( 'gform_after_submission', function ( $entry, $form ) {

    foreach ( $form['fields'] as $field ) {
        $field_value = $field->get_value_export( $entry, $field->id, true );
        // do something with the field value.
    }

}, 10, 2 );

Leave a Comment