kumarrana Posted January 21, 2008 Share Posted January 21, 2008 It seems stupid but I could not debug form validation. Code looks like this function verify_user_input() { if($_POST['title'] == "") { $error = "Blank title not allowed"; echo $error; } else if($_POST['category'] == "") { $error = "Blank Category Not allowed"; echo $error; } else if($_POST['body'] == "") { $error = "Empty body not allowed"; echo $error } else { echo "<br> New post submitted successfully"; } } This code cold not validate $_POST['body'] part, others work fine. Form input for this part look like this; echo "<textarea name = body cols = 40 rows = 15> </textarea> <br><br>"; Any idea what is wrong? Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/ Share on other sites More sharing options...
adam291086 Posted January 21, 2008 Share Posted January 21, 2008 is the body text area being passed across from your forms. Try echoing out $_POST['body'] and see what you get? Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-444988 Share on other sites More sharing options...
PHP Monkeh Posted January 21, 2008 Share Posted January 21, 2008 Missing semi-colon on the end of echo $error after your else if($_POST['body'] == "") Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-444989 Share on other sites More sharing options...
mmarif4u Posted January 21, 2008 Share Posted January 21, 2008 $error = "Empty body not allowed"; echo $error; echo "<textarea name = 'body' cols = 40 rows = 15> </textarea> <br><br>"; Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-444990 Share on other sites More sharing options...
kumarrana Posted January 21, 2008 Author Share Posted January 21, 2008 Yes it echos $_POST['body'] part. Sorry for confusion it compiles and runs; I missed semicolon while copying and pasting. Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-444993 Share on other sites More sharing options...
kumarrana Posted January 21, 2008 Author Share Posted January 21, 2008 I am ganna give you full code, may be that will help more. Rest of the code works besides validating body of the form. ($_POST['body']) function verify_user_input() { echo "<br> Post: >". $_POST['body']; if($_POST['title'] == "") { $error = "Blank title not allowed"; echo $error; } else if($_POST['category'] == "") { $error = "Blank Category Not allowed"; echo $error; } else if($_POST['body'] == "") { echo "Empty body not allowed"; } else { echo "<br> New post submitted successfully"; } } verify_user_input(); //dump_in_mysql_post(); } else { echo "Submit Blog Entry"; echo "<form action=\"$PHP_SELF\" method=\"POST\">"; echo "Title: <input type = text name = title> <br><br>"; echo "Category: <input type = text name = category><br><br>"; echo "Body: <br><br>"; echo "<textarea name = body cols = 40 rows = 15> </textarea> <br><br>"; echo "<input name=submit type=submit value=New Post>"; echo "</form>"; } Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-444996 Share on other sites More sharing options...
quickstopman Posted January 21, 2008 Share Posted January 21, 2008 here's what always works for me i use an array to hold all the errors so <?php function verify_user_input() { $errors = array(); echo "<br> Post: >". $_POST['body']; if($_POST['title'] == ""){ $errors[] = "Blank title not allowed"; } if($_POST['category'] == ""){ $errors[] = "Blank Category Not allowed"; } if($_POST['body'] == ""){ $errors[] = "Empty body not allowed"; } if(empty($errors) { echo "<br> New post submitted successfully"; } else { foreach ($errors as $error) { echo "- ". $error; } } verify_user_input(); ?> hope that helped! -Zack Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-445044 Share on other sites More sharing options...
resago Posted January 21, 2008 Share Posted January 21, 2008 Form validate on the client first, then on the server. Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-445275 Share on other sites More sharing options...
kumarrana Posted January 21, 2008 Author Share Posted January 21, 2008 Thaks a bunch. I think I am ganna stick with your code. Link to comment https://forums.phpfreaks.com/topic/87020-solved-form-validation/#findComment-445387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.