To prefill radio buttons, checkboxes, dropdowns or multi-select fields in Gravity Forms you will need to the filter hooks provided by Gravity Forms.
How to prefill a radio box:
In Gravity Forms, open the form builder, select your radio field, click the “Advanced Tab”.
Enable “Allow field to be populated dynamically” and fill in for example “callback_mbr_db_radio”.
You can enter whatever you want but dashes and white spaces are not allowed.
In your child theme’s functions.php, you need to insert the following PHP code.
/* * "callback_mbr_db_radio" must match whatever you entered in "Advanced Tab" of your form. */ add_filter( 'gform_field_value_callback_mbr_db_radio', 'mbr_populate_mbr_db_radio' ); function mbr_populate_mbr_db_radio( $value ) { return do_shortcode( '[mbr_db_radio]' ); } </code>
How to prefill a checkbox:
In Gravity Form, open the form builder, select your checkbox field, click the “Advanced Tab”.
Enable “Allow field to be populated dynamically” and fill in for example “callback_mbr_db_checkbox”.
You can enter whatever you want but dashes and white spaces are not allowed.
In your child theme’s functions.php file, you need to insert the following PHP code.
/* * "callback_mbr_db_checkbox" must match whatever you entered in "Advanced Tab" of your form. */ add_filter( 'gform_field_value_callback_mbr_db_checkbox', 'mbr_populate_mbr_db_checkbox' ); function mbr_populate_mbr_db_checkbox( $value ) { $arr_checkbox = do_shortcode( '[mbr_db_checkbox]' ); $arr_checkbox = array_filter( explode( '||', $arr_checkbox ) ); return $arr_checkbox; } </code>
How to prefill a dropdown:
In Gravity Forms, open the form builder, select your dropdown field, click the “Advanced Tab”.
Enable “Allow field to be populated dynamically” and fill in for example “callback_mbr_db_dropdown”.
You can enter whatever you want but dashes and white spaces are not allowed.
In your child theme’s functions.php, you need to insert the following PHP code.
/* * "callback_mbr_db_dropdown" must match whatever you entered in "Advanced Tab" of your form. */ add_filter( 'gform_field_value_callback_mbr_db_dropdown', 'mbr_populate_mbr_db_dropdown' ); function mbr_populate_mbr_db_dropdown( $value ) { return do_shortcode( '[mbr_db_dropdown]' ); } </code>
How to prefill a multi-selectbox:
In Gravity Forms, open the form builder, select your multi-select field, click the “Advanced Tab”.
Enable “Allow field to be populated dynamically” and fill in for example “callback_mbr_db_multiselect”.
You can enter whatever you want but dashes and white spaces are not allowed.
In your child theme’s functions.php, you need to insert the following PHP code.
/* * "callback_mbr_db_multiselect" must match whatever you entered in "Advanced Tab" of your form. */ add_filter( 'gform_field_value_callback_mbr_db_multiselect', 'mbr_populate_mbr_db_multiselect' ); function mbr_populate_mbr_db_multiselect( $value ) { $arr_multiselect = do_shortcode( '[mbr_db_multiselect]' ); $arr_multiselect = array_filter( explode( '||', $arr_multiselect ) ); return $arr_multiselect; } </code>