Help with php validation logic please

I have a field that appears on the page, only if the user selects a specific option.
(javascript).

If the user selects that specific option, the field is required, hence, it cannot be empty.

If the user selects other option, the field doesn’t appear, hence, it cannot be required.

How can we establish this relation on the php validation side, telling that, when a specific select value is in place, validate/don’t validate another form field.

The select options are stored on this array:
$dominio_ref=$_POST[‘dominio2’];

We can access a specific property of this array by doing:
$dominio_ref[11] for the option number eleven (from 0).

Will isset($dominio_ref[11]) do the trick?

I cannot test it because this system is quite a mess and I cannot replicate locally.

Please advice,
Márcio

Ya, you first detect if the selected option has dependencies. If it does, then you also validate the dependencies.


if (isset($_POST['employment_status'])) {
    if ($_POST['employment_status'] == 'employed' && (!isset($_POST['income']) || !validate_income($_POST['income']))) {
        //dependancy criteria not met
    }
}

Thanks a lot,

That’s what distinguishes the programmers from the “others” like me.
You can logically and “programmaticly” solve the issues.

Thanks again,
Márcio

You’ll get there. I’m not gifted, I’m just stubborn and persistent lol.