I am trying to set the state of a specific checkbox in a form to selected based on it’s value matching a string, all the below does is return three arrays (the number of choices in this checkbox field)
// https://docs.gravityforms.com/gf_field_checkbox/
// https://docs.gravityforms.com/gform_field_choice_markup_pre_render/
// https://community.gravityforms.com/t/ive-set-isselected-1-on-form-render-but-this-is-not-showing-on-the-form-resolved/13291
// https://stackoverflow.com/questions/60851099/gravity-forms-pre-selected-choices-checkboxes-field
// https://www.gravityforms.com/blog/dynamic-population-tutorial/
add_filter( 'gform_field_choice_markup_pre_render_3_7', function ( $choice_markup, $choice, $field, $value ) {
foreach( $form['fields'] as &$field ) {
if($field->id == 7) {
$options = $field["choices"];
foreach ( $options as $fkey => $option ) {
if( $option['value'] == 'Biotechnology'){
$choices[] = array( 'text' => $option['text'], 'value' => $option['value'], 'isSelected' => true );
} else {
$choices[] = array( 'text' => $option['text'], 'value' => $option['value'], 'isSelected' => false );
}
}
$field->choices = $choices;
}
}
return $form;
}, 10, 4 );
Another way of doing this woule be to populate form A with an existing entry for form A. But the link below doesn’t talk about populating the fields with what the user entered previously