Forum Moderators: coopster
can someone suggest a method or point me in the right direction for validating a simple form using php.
I have a form which only has two significant fields - a drop down with three choices, and a dropdown with five choices - and I want the user to have chosen the correct value from the first dropdown before allowing the form to be submitted : ideally, on choosing the incorrect value, the page will display "incorrect please try again" or something along those lines.
the form is like this :
<form action="http://www.domain.com/details.php" method="post" name="id">
<div align="center">
<input type="hidden" name="cc" value="RX">
<input type="hidden" name="co" value="RXS">
</div>
<p align="center">To enter, just answer this simple question:
<p align="center"><b>What year did England win the World Cup? </b></p>
<p align="center">Your Answer
<select name="sa">
<option value="1966">1966</option>
<option value="1968">1968</option>
<option value="1969">1869</option>
</select>
</p>
<p align="center"> <span class="style6">I would like</span>
<select name="quantity">
<option value="1.00">1 ticket</option>
<option value="2.00">2 tickets</option>
<option value="3.00">3 tickets</option>
<option value="4.00">4 tickets</option>
<option value="5.00">5 tickets</option>
</select>
<br>
</p>
<p align="center"> </p>
<p align="center"> <a href="javascript:document.id.submit();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('enter','','Flash/enterbutton_On.gif',1)"><img src="Flash/enterbutton_Off.gif" alt="Go!" name="enter" width="85" height="77" border="0"></a> </p>
</form>
Not the toughest question in the world but thats not what I'm after.
Ideally I would like the "submit" button to be inactive until such point as they have chosen the correct answer, or if they submit with an incorrect answer they get the "incorrect" message.
I'm not sure if this is even possible : if someone can tell me how to do it thats great, but if not maybe just point me in the right direction?
Thanks again
What I would do is only show the first part of the form ...
<select name="sa">
<option value="1966">1966</option>
<option value="1968">1968</option>
<option value="1969">1869</option>
</select>
</p>
... with a submit button.
Check the validity of the 'sa' value, then refresh and show the rest of the form ...
<p align="center"> <span class="style6">I would like</span>
<select name="quantity">
<option value="1.00">1 ticket</option>
<option value="2.00">2 tickets</option>
<option value="3.00">3 tickets</option>
<option value="4.00">4 tickets</option>
<option value="5.00">5 tickets</option>
</select>
This will insure that the question is answered correctly before the choice for tickets is given.
I dont really want to use JS, would rather stick with php if poss.
How might I go about doing it? Sorry I dont want all the information for free, just maybe pointed in the right direction as to be honest I havent got a clue where to start : very new to php.
That way I could get around it because a correct answer would take them to the correct page, an incorrect answer would allow me to direct them to another page, perhaps with an automatic redirection back to the first page?
Is that plausible? or even a good idea?
Its a drop-down menu that jumps to a specified url as soon as the value is selected in the dropdown or when the button attached to said menu is clicked
It looks like this :
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<option value="page3.htm">page3</option>
<option value="page2.htm">page2</option>
<option value="page1.htm">page1</option>
</select>
<input type="button" name="Button1" value="Go" onClick="MM_jumpMenuGo('menu1','parent',0)">
and I didnt know if it would be possible to modify the onClick to work as a submit as well.
[x-code.com...]
It has solved one validation issue I had on another page, but the problem with the existing page (the one on this thread) remains.
One remaining question : Would this be easier if I had radio buttons rather than a drop-down?
IE :- choosing button A allow the form to be processed, buttons B or C get the from redisplayed with "incorrect" beside the buttons?