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!
It’s hard to help without your code… but, I imagine you’re hiding a part of a form with JavaScript. If that’s the case, then the hidden elements won’t be posted back to your PHP script.
So, in your PHP, you would do something like:
if ($_POST['your-select-box'] == 'value1') {
echo "validate form with value 1";
} else {
echo "validate form with value 2";
}
Oh really! So if it’s display none - either via CSS or js then the php won’t parse the hidden inputs? If that’s the case then that makes it very simple.
Turns out I was wrong (kinda). I didn’t do front end dev for a couple of years so I guess I’m rusty
You need to disable the field if you don’t want it to be posted. Here’s an example: