Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End What's form validation process when showing portion of form depending on select? Reply To: What's form validation process when showing portion of form depending on select?

#170603
__
Participant

Just use a branch in your logic. For example, if you can select “letters” to choose options “a”, “b”, and “c”, or select “numbers” to select “1”, “2”, and “3”, then your validation structure might look something like this (pseudocode):

if( $_POST['select'] === 'letters' ){
    validate( $_POST['a'] );
    validate( $_POST['b'] );
    validate( $_POST['c'] );
}
elseif( $_POST['select'] === 'numbers ){
    validate( $_POST['1'] );
    validate( $_POST['2'] );
    validate( $_POST['3'] );
}

You can follow a similar approach in javascript, though the specific plugin you choose might already have a way to deal with such things (you should look into that).