What's the 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!

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 :wink:
You need to disable the field if you don’t want it to be posted. Here’s an example:

<!DOCTYPE html>
<title>Testing hidden values</title>
#value1 {

#value3 {

<form action="index.php" method="post">
<input type="text" name="value1" value="value1" id="value1"><br>
<input type="text" name="value2" value="value2" id="value2"><br>
<div id="value3">
	<input type="text" name="value3" value="value3"><br>

<input type="text" name="value4" value="value4" id="value4"><br>
<input type="text" name="value5" value="value5" id="value5"><br>
<input type="submit" value="submit" name="submit">

	document.getElementById("value2").style.display = "none";

	document.getElementById("value4").style.display = "none";
	document.getElementById("value4").disabled = true;

The field #4 won’t be posted, all of the others will. Hope this help :slight_smile:

Thnaks bro