I have added checkboxes dynamically to Gravity form but when i select last 2 items and click submit i got error message "this field is required". If i select 1st item or 2nd , 3rd then no error and form is submitted successfully.
Here is my php code.
add_filter( 'gform_pre_render_56', 'get_menu_options' );
add_filter( 'gform_pre_validation_56', 'get_menu_options' );
add_filter( 'gform_pre_submission_filter_56', 'get_menu_options' );
function get_menu_options($form){
/****get all beverages from post*****/
$beverages = array_filter( get_post_meta(get_the_ID(), 'wpcf-beverages', false) );
$form['fields'][22]->choices = set_field_choices($beverages);
return $form;
}
function set_field_choices($values){
$field_choices = array();
$isSelected = (count($values) == 1)?true:false;
foreach ($values as $value) {
$field_choices[] = array(
'text' => $value,
'value' => $value,
'isSelected' => $isSelected
);
}
return $field_choices;
}
Here is page link
Thanks
Ok, i figured out the problem. we need to keep eye on input id