aeafisme23 Posted May 9, 2006 Share Posted May 9, 2006 This code works if i keep the action set to form.php which is the same page. But i want it to go to process.php (action="process.php") and echo the results. HOWEVER, if i change the action to another page it will not validate. Any ideas, suggestions?[code]........FORM.PHP.......<br><form method="POST" action="form.php"><table border="0" cellpadding="0" cellspacing="0" bordercolor="#000000" width="600" > <tr> <td width="100" align="right">User Name:</td> <td width="25"> </td> <td width="200"> <input type="text" name="user_name_input" size="30" value="<? echo $user_name_input; ?>"></td> <td width="275"> <? // only validate form when form is submitted if(isset($submit_button)){ $error_msg=''; if(trim($user_name_input)=='' || strlen(trim($user_name_input)) < 3 || strlen(trim($user_name_input)) > 12) { $error_msg.="Username must be 3 to 12 chars. long<br>"; } // display error message if any, if not, proceed to other processing if($error_msg==''){ // other process here } else { echo "<font color=red>$error_msg</font>"; } } ?> </td> </tr> <tr> <td width="100" align="right">Email:</td> <td width="25"> </td> <td width="200"> <input type="text" name="email_input" size="20" value="<? echo $email_input; ?>"></td> <td width="275"> <?// only validate form when form is submittedif(isset($submit_button)){ $error_msg=''; if(trim($email_input)=='') { $error_msg.="Please enter an email<br>"; } else { // check if email is a valid address in this format username@domain.com if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) $error_msg.="Please enter a valid email address<br>"; } // display error message if any, if not, proceed to other processing if($error_msg==''){ // other process here } else { echo "<font color=red>$error_msg</font>"; }}?></td> </tr> <tr> <td width="100"> </td> <td width="25"> </td> <td width="200"> <input type="submit" value=" Submit " name="submit_button"></td> <td width="275"> </td> </tr></table></form>[/code] Quote Link to comment Share on other sites More sharing options...
jeremywesselman Posted May 9, 2006 Share Posted May 9, 2006 It does not validate when you change the form action because all of your validation process is located on this page. If you try to change the action, once the submit button is clicked, it automatically goes to the form action page.To fix this, you need to move all of your form processing to the other page. OR just echo the data after it is processed with this page.[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.