condition before submitting php form

Excalibur!

New Member
I have a page with an options menu, however would like the user to pass the captcha test. Currently i want it so the user enters atleast 3 characters in the textbox or else they would not be able to submit the form, the code is shown below with the php condition at the end of the form. However i know i have obviously got it wrong. Is there anyway to do this without pasting the php code on another page? Thanks. \[code\]<?php// Check to see if the form has been submitted.if(isset($_POST['menu1'])) { // If the form has been submitted, force a re-direct to the choice selected. header('Location: ' . $_POST['menu1']);}?><div style="padding-left: 50px"><p class="arial"><strong></strong><br /><br /></p><form method="post"> <table class="freecontact2form" border="0" width="400px"><tbody><tr><td colspan="2"><span style="font-size: x-small;"> </span> <font color=#000000 >Which of the following do you want to use?</font> <br /><br /></td></tr><tr> <td valign="top"><table width="400px" class="freecontact2form"> <tr> <td colspan="2"><br /> <br /> <div class="freecontact2formmessage"> </div></td> </tr> <tr> <td valign="top"><label for="menu1" >The options are:<span class="required_star"> </span></label></td> <td valign="top"><select name="menu1" id="menu1"> <option selected="selected" value ="http://www.google.com">Google </option> <option value ="http://www.yahoo.com">Yahoo</option> <option value ="http://www.bing.com">Bing</option> </select></td> </tr> <tr> <td valign="top"><label for="captcha" ><span class="required_star"></span><span class="required_star"></span></label></td> <td valign="top"><BR /><BR /><img src="http://stackoverflow.com/questions/15557812/captcha.jpg" /></td> </tr> <tr> <td>Please enter the characters shown in the CAPTCHA image:</td> <td><input type="text" name="captcha" id="captcha" value="" size="10" /> </td> </tr> <tr> <td style="text-align:center" colspan="2"><br /><br /> <input type="submit" value="http://stackoverflow.com/questions/15557812/Submit"> </td> </tr> </table></td> <td valign="top">&nbsp;</td></tr></tbody></table></form> <br /><p> </p><p> </p><?phpif(isset($_POST['menu1'])) { function died($error) { echo "Sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } if(!isset($_POST['menu1']) || !isset($_POST['captcha']) ) { died('Sorry, there appears to be a problem with your form submission.'); } $error_message = ""; if(strlen($captcha) < 3) { $error_message .= 'Please ensure the captcha entered is at least 3 characters long'; } if(strlen($error_message) > 0) { died($error_message); }?><?php}die();?>\[/code\]
 
Back
Top