Multi-page, Click on the next button without filling the necessary fields, validate anyway

Hello,

All are in the title,
I have multi-page form, I have created a php code that allows a field to be required or not if another field is valid. The field is marked as required, but clicking on the next button still takes you to the next page without filling in the fields.

Here are my different codes that I tried without success :

add_filter('gform_validation_1', 'populate_from_entriesForm');
add_filter('gform_pre_render_1', 'populate_from_entriesForm');
function populate_dropdown_from_entriesForm($form)
{
    $current_page = GFFormDisplay::get_current_page($form['id']);

    if ($current_page == 5) {
        $entry = RGFormsModel::get_current_lead();
        foreach ($form['fields'] as &$field) {
            switch ($field->id) {
                case 53:
                    $old_value = rgar($entry, 100);
                    break;
                case 54:
                    $old_value = rgar($entry, 101);
                    break;
                case 55:
                    $old_value = rgar($entry, 102);
                    break;
                case 56:
                    $old_value = rgar($entry, 106);
                    break;
                case 57:
                    $old_value = rgar($entry, 104);
                    break;
                case 58:
                    $old_value = rgar($entry, 105);
                    break;
                default:
                    continue;
            }
            
            if ($field['type'] == 'fileupload') {
                if ($old_value == "") {
                    $field->isRequired = true;
                    $field->description = " ";
                } else {
                    if ($field->id == 56) {
                        $links = explode(" ", $old_value);
                        $link_list = "";
                        foreach ($links as $link) {
                            $link_list .= "<b><a href='{$link}' style='color:#3a7d34';>nah</a></b> ";
                        }
                        $field->isRequired = false;
                        $field->description = "Vos fichiers enregistrés : " . $link_list;
                    } else {
                        $field->isRequired = false;
                        $field->description = "nah";
                    }
                }
            }
        }
    }

    return $form;
}

Take a look at the documentation for gform_pre_validation:

Follow that example, and use gform_pre_validation rather than gform_validation.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.