rhock_95 Posted September 22, 2007 Share Posted September 22, 2007 Is there a simple way to prevent an html form from being submitted (without javascript) if no text is entered? <form action="peop_search.php" method="post"> <input type="text" name="query" /> <input type="submit"> </form> If an invalid query is entered it prints the message below but if nothing is enterd it prints all the records if ($numrows == 0){ echo("No results found matching your query - $query"); Is there any way to amend this to echo the above if nothing is entered? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/ Share on other sites More sharing options...
dsaba Posted September 22, 2007 Share Posted September 22, 2007 if (isset($_POST)) { //do any kind of manipulation and output with the posted form data //like checking for correct/empty form fields } else { //if nothing is being posted, the form is then displayed } PHP is server side, you can only "change" things once a page has been loaded/reloaded, so once the form has been posted you can then decide what to do with the data, Javascript on the other hand can stop the form from being submitted in real time, but i assum ethat is really now what u want, u can still have the form submitted, but just give the impression of it not being submitted if incorrect data has been submitted and u can just simply redisplay the form like it was never submitted perception is the keyword Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-352753 Share on other sites More sharing options...
rhock_95 Posted September 22, 2007 Author Share Posted September 22, 2007 Thanks for the reply... //like checking for correct/empty form fields Ho do I do this? this is actually the crux of what I am seeking Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-352764 Share on other sites More sharing options...
dsaba Posted September 22, 2007 Share Posted September 22, 2007 $var = ""; if (empty($var)) { echo 'its empty'; } if ($var == "") { echo 'its empty'; } if (strlen($var) == 0) { echo 'its empty'; } if ($var != "correct data") { echo 'u get it'; } Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-352824 Share on other sites More sharing options...
rhock_95 Posted September 22, 2007 Author Share Posted September 22, 2007 Thanks again for the efforts... but the script still retrieves all the records...it also prints out ALL the messages... any ideas? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353027 Share on other sites More sharing options...
rarebit Posted September 22, 2007 Share Posted September 22, 2007 can u show code? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353029 Share on other sites More sharing options...
MmmVomit Posted September 22, 2007 Share Posted September 22, 2007 It would be helpful to see more code, especially the query you're using. You might try using something like this. if(!isset($_POST['query']) || $_POST['query'] == "") { echo "No results found matching your query - $query"; } else { // process query using $_POST['query'] } Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353030 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 <?php if ($_POST[variable]=="") { $error[variable]="Please enter the variable";} else { unset($error[variable]);} if ($error){ ?> html form <?php }else{ insert record ;} ?> Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353031 Share on other sites More sharing options...
rhock_95 Posted September 22, 2007 Author Share Posted September 22, 2007 Thanks for the reply... with that I get nothing but line errors (like a missing curly bracket) but I can't seem to resolve the errors exactly how would I incorporate this into my script? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353036 Share on other sites More sharing options...
rarebit Posted September 22, 2007 Share Posted September 22, 2007 Would help to see the script! Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353037 Share on other sites More sharing options...
rhock_95 Posted September 22, 2007 Author Share Posted September 22, 2007 It would be helpful to see more code, especially the query you're using. You might try using something like this. if(!isset($_POST['query']) || $_POST['query'] == "") { echo "No results found matching your query - $query"; } else { // process query using $_POST['query'] } This Almost works... what it does is print the "No results found matching your query" above each record...but it is still printing all the records Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353084 Share on other sites More sharing options...
JJohnsenDK Posted September 22, 2007 Share Posted September 22, 2007 post all your code mate... we most see the posts you are making too.. Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353086 Share on other sites More sharing options...
rhock_95 Posted September 22, 2007 Author Share Posted September 22, 2007 I would like to oblige but the script is so loaded with my own personal comments it would take me half an hour just to strip all the comments... is there a particula part of the script that would help specifically? the script queries a database for a single column but has pagination results... Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353097 Share on other sites More sharing options...
darkfreaks Posted September 22, 2007 Share Posted September 22, 2007 did u use my code? please list the errors wrong with it. Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353110 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 did u use my code? please list the errors wrong with it. Yes thanks for the efforts... it throws numorious line errors starting with }else{ insert record ;} Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353114 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 lol show me your code only way we can help. Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353117 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 what part of the script? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353119 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 show me everything before the html form php wise Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353121 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 sorry I can't do that...without stripping all the comments the html form is a different page/file the action of the form(page) calls the script some of the suggestions in already posted print the error message but the script still returns all the records Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353123 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 what do you want it to error? like if you dont fill in the form or what? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353126 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 try <?php if empty($_POST[variable]||$_POST[variable2]) { echo "sorry you must fill in the form";} ?> Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353127 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 exactly if the form is submitted with no entry in the form field display message Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353128 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 try my above code ^ Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353130 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 try <?php if empty($_POST[variable]||$_POST[variable2]) { echo "sorry you must fill in the form";} ?> that throws a line error regardless of where in the script I set it Parse error: parse error, expecting `'('' Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353131 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 please specify the line of the error and paste that line here Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/#findComment-353133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.