- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Back End’ is closed to new topics and replies.
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?
What’s the form validation process when showing portion of form depending on select option selected?
So googling I can find the hide and show bit using the select input. I have a good back end form processing code. So my question is how do I tell the php form processing code to only validate what was selected via the select input and no also all the stuff hidden on the page? I am also using jQuery validation so this question is for the js end too?
If it’s relatively simple then I’ll just do swap the inputs depending on selection made. If it’s too complicated then I may have to just have two forms on different pages. Thanks!
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).
thanks bro