Hello, here is my problem. I have a form, and when showing the form on page, I need to hide some of the fields. I am using the "gform_pre_render" filter for this, as I found a lot of reference that it should be used for this. It works at the first sight and the fields are really hidden, but it seems that it only filters fields when the form is displayed, but when I submit the form and it goes through validation, it is validated according to old fields settings instead of the filtered ones. It is no matter if I just unset the fields from form or I set their "isRequired" value to false, always the forms displays correctly, but the validation fails, because required fields are just missing.
Here is my code I am using:
function ins_remove_fields($form) {
$fields_to_hide = array('test');
// remove fields to hide
foreach($form['fields'] as $key=>$field) {
if(in_array($field['label'], $fields_to_hide)) {
unset($form['fields'][$key]);
//$form['fields'][$key]['isRequired'] = false;
}
}
return $form;
}
add_filter('gform_pre_render', 'ins_remove_fields');
while "test" is the name of one of the required fields.
Do you have any idea what I might be doing wrong ? I think it should be correct like this, but apparently it is not.
Thank you in advance