codeboy89 Posted November 20, 2009 Share Posted November 20, 2009 Below is my current form error handling, I have some other functions that run after this code, and currently the error handling for "Form was incomplete" and the strings too long will mix with the functions after this snippet. How do I run these in order and not allow anything to run if they are printed. In case I lost you, what is happening, if I do not type the CAPTCHA, "Code was invalid" returns and I can complete the form again, but if I fill out everything except $name, "Form was incomplete" returns and the functions in my script next still run. CODE: $name = trim(strip_tags($_POST['name'])); $link = trim(strip_tags($_POST['link'])); $code = trim(strip_tags($_POST['code'])); if (trim(strip_tags($_POST['code'])) != $_SESSION['cap']) { print "Code was invalid</div></body></html>"; exit(); } if (trim(strip_tags(!preg_match("/http:\/\//",$_POST['link'])))) { print "Link was invalid</div></body></html>"; exit(); } if (( $name == "") || ( $link == "") || ( $code == "")) { print "Form was incomplete</div></body></html>"; } elseif (strlen($name) > 25) { print "Name too long</div></body></html>"; } elseif (strlen($link) > 150) { print "Link too long</div></body></html>"; } elseif (strlen($code) > 6) { print "Code too long</div></body></html>"; } Link to comment https://forums.phpfreaks.com/topic/182241-need-help-fixing-error-handling/ Share on other sites More sharing options...
Cardale Posted November 20, 2009 Share Posted November 20, 2009 Try this. $name = trim(strip_tags($_POST['name'])); $link = trim(strip_tags($_POST['link'])); $code = trim(strip_tags($_POST['code'])); if (trim(strip_tags($_POST['code'])) != $_SESSION['cap']) { print "Code was invalid</div></body></html>"; exit(); } if (trim(strip_tags(!preg_match("/http:\/\//",$_POST['link'])))) { print "Link was invalid</div></body></html>"; exit(); } if (( $name == "") || ( $link == "") || ( $code == "")) { print "Form was incomplete</div></body></html>"; exit(); } elseif (strlen($name) > 25){ print "Name too long</div></body></html>"; exit(); } elseif (strlen($link) > 150){ print "Link too long</div></body></html>"; exit(); } elseif (strlen($code) > 6){ print "Code too long</div></body></html>"; exit(); } Link to comment https://forums.phpfreaks.com/topic/182241-need-help-fixing-error-handling/#findComment-961687 Share on other sites More sharing options...
codeboy89 Posted November 20, 2009 Author Share Posted November 20, 2009 that works for the error handling, but then the form will not submit correctly, HERE is the full code, showing what takes place after error handling... <?php session_start(); $name = trim(strip_tags($_POST['name'])); $link = trim(strip_tags($_POST['link'])); $code = trim(strip_tags($_POST['code'])); if (trim(strip_tags($_POST['code'])) != $_SESSION['cap']) { print "Code was invalid</div></body></html>"; exit(); } if (trim(strip_tags(!preg_match("/http:\/\//",$_POST['link'])))) { print "Link was invalid</div></body></html>"; exit(); } if (( $name == "") || ( $link == "") || ( $code == "")) { print "Form was incomplete</div></body></html>"; exit(); } elseif (strlen($name) > 25){ print "Name too long</div></body></html>"; exit(); } elseif (strlen($link) > 150){ print "Link too long</div></body></html>"; exit(); } elseif (strlen($code) > 6){ print "Code too long</div></body></html>"; exit(); } else { $file_name = "post.xml"; $file_pntr = fopen($file_name, "r+"); $lock = flock($file_pntr, LOCK_EX); $file_read = fread($file_pntr, filesize($file_name)); $date = date ("j M Y"); $post = "\n\n<ponmurt>\n<p><a href=\"$link\" target=\"_blank\">$name</a><br />on $date</p>\n</ponmurt>"; $post = stripslashes($post); fwrite($file_pntr, "$post"); fclose($file_pntr); print "<head><meta http-equiv=\"refresh\" content=\"0; url=index.php\" /></head>"; } ?> Link to comment https://forums.phpfreaks.com/topic/182241-need-help-fixing-error-handling/#findComment-961789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.