marcus Posted September 23, 2007 Share Posted September 23, 2007 $var = $_POST['variable']; $var2 = $_POST['variable2']; $errors = array(); if(!$var){ $errors[] = "Var one is missing!"; } if(!$var2){ $errors[] = "Var two is missing!"; } if(count($errors) > 0){ foreach($errors AS $error){ echo "<font color=\"red\">$error</font><br>\n"; } }else { echo "both variables are set, you're ready for take off!\n"; } Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353134 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 please specify the line of the error and paste that line here 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/page/2/#findComment-353136 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 $var = $_POST['variable']; $var2 = $_POST['variable2']; $errors = array(); if(!$var){ $errors[] = "Var one is missing!"; } if(!$var2){ $errors[] = "Var two is missing!"; } if(count($errors) > 0){ foreach($errors AS $error){ echo "<font color=\"red\">$error</font><br>\n"; } }else { echo "both variables are set, you're ready for take off!\n"; } Can you explain how to use this snippet? do I have to declare the variables? if so how? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353137 Share on other sites More sharing options...
marcus Posted September 23, 2007 Share Posted September 23, 2007 Just define the variables that correspond with your form field names. $name = $_POST['form_field_name_one']; //etc.... To see if a value exists just implement the 5th and 6th of my example to fit your own. If you have more than two just continue adding sets of line five and six to meet your requirements Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353138 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 there is only one variable "$query" Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353139 Share on other sites More sharing options...
gromer Posted September 23, 2007 Share Posted September 23, 2007 <?php $self = $_SERVER['PHP_SELF']; $query = $_POST['query']; if (isset($query)) { // Do stuff with $query // Redirect somewhere when done. } else { echo "You must fill in the form."; } ?> <html> <head> <title>A form</title> </head> <body> <form action="<?php echo $self; ?>" method="post"> <input type="text" name="query" /> <input type="submit"> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353140 Share on other sites More sharing options...
marcus Posted September 23, 2007 Share Posted September 23, 2007 Then just remove line five or six and replace it with your own variable/error. Using PHP_SELF can be a bad move since the user could implement his or her own code into the URL. Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353141 Share on other sites More sharing options...
darkfreaks Posted September 23, 2007 Share Posted September 23, 2007 i agree stick with post <?php $query=$_POST['query']; if empty($query) { echo "error message here";} ?> Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353142 Share on other sites More sharing options...
gromer Posted September 23, 2007 Share Posted September 23, 2007 Then just remove line five or six and replace it with your own variable/error. Using PHP_SELF can be a bad move since the user could implement his or her own code into the URL. Can y'all explain this more? How could a user put more code in the URL? What's the best alternative for PHP_SELF? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353143 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 i agree stick with post <?php $query=$_POST['query']; if empty($query) { echo "error message here";} ?> throws a line error Parse error: parse error, expecting `'('' if empty($query) { echo "error message here";} Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353144 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 <?php $self = $_SERVER['PHP_SELF']; $query = $_POST['query']; if (isset($query)) { // Do stuff with $query // Redirect somewhere when done. } else { echo "You must fill in the form."; } ?> <html> <head> <title>A form</title> </head> <body> <form action="<?php echo $self; ?>" method="post"> <input type="text" name="query" /> <input type="submit"> </form> </body> </html> the form is just an html doc it calls the script from the action parameter Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353146 Share on other sites More sharing options...
gromer Posted September 23, 2007 Share Posted September 23, 2007 <?php $self = $_SERVER['PHP_SELF']; $query = $_POST['query']; if (isset($query)) { // Do stuff with $query // Redirect somewhere when done. } else { echo "You must fill in the form."; } ?> <html> <head> <title>A form</title> </head> <body> <form action="<?php echo $self; ?>" method="post"> <input type="text" name="query" /> <input type="submit"> </form> </body> </html> the form is just an html doc it calls the script from the action parameter Exactly. You said you wanted it to show the form again if nothing was submitted. This checks that and then redirects to wherever you want if the data is correct. You should consider doing js data validation too... Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353148 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 <?php $self = $_SERVER['PHP_SELF']; $query = $_POST['query']; if (isset($query)) { // Do stuff with $query // Redirect somewhere when done. } else { echo "You must fill in the form."; } ?> <html> <head> <title>A form</title> </head> <body> <form action="<?php echo $self; ?>" method="post"> <input type="text" name="query" /> <input type="submit"> </form> </body> </html> the form is just an html doc it calls the script from the action parameter Exactly. You said you wanted it to show the form again if nothing was submitted. This checks that and then redirects to wherever you want if the data is correct. You should consider doing js data validation too... so where does this code call the script? Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353151 Share on other sites More sharing options...
gromer Posted September 23, 2007 Share Posted September 23, 2007 so where does this code call the script? Eh, can you tell me exactly what you need? I reread your original post and you say that you want it to display an error if nothing is entered but also append that error to the top of the form? Not really sure what you need. Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353152 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 so where does this code call the script? Eh, can you tell me exactly what you need? I reread your original post and you say that you want it to display an error if nothing is entered but also append that error to the top of the form? Not really sure what you need. I just want the script to return a message stating the form was submitted without any data...please click the back button and try again...etc right now everything I have tried still pulls down all the records...some of the snippets I've tried print the error message but the script still pulls down all the records and some even when a valid query is entered it still prints the error message Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353155 Share on other sites More sharing options...
marcus Posted September 23, 2007 Share Posted September 23, 2007 They could end the script. URL could be: file.php?inj="><h1>WTH</h1><br>DONTFAIL Making the script read: <form action="file.php"><h1>WTH</h1><br>DONTFAIL" method="post"> Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353156 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 They could end the script. URL could be: file.php?inj="><h1>WTH</h1><br>DONTFAIL Making the script read: <form action="file.php"><h1>WTH</h1><br>DONTFAIL" method="post"> I have no idea what this is, sorry Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353161 Share on other sites More sharing options...
gromer Posted September 23, 2007 Share Posted September 23, 2007 So all you would need to do to my code above is change the action to some other php file and put my php code in it, sans the $self line. Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353176 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 So all you would need to do to my code above is change the action to some other php file and put my php code in it, sans the $self line. the (HTML) needs to be a different doc...otherwise the pagination menu/display is printed Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353179 Share on other sites More sharing options...
gromer Posted September 23, 2007 Share Posted September 23, 2007 So all you would need to do to my code above is change the action to some other php file and put my php code in it, sans the $self line. the (HTML) needs to be a different doc...otherwise the pagination menu/display is printed That's what I said to do. Put the php code in a separate file where the form points to in the action field. Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353211 Share on other sites More sharing options...
rhock_95 Posted September 23, 2007 Author Share Posted September 23, 2007 So all you would need to do to my code above is change the action to some other php file and put my php code in it, sans the $self line. the (HTML) needs to be a different doc...otherwise the pagination menu/display is printed That's what I said to do. Put the php code in a separate file where the form points to in the action field. It does not work... it still prints all the records Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353345 Share on other sites More sharing options...
gromer Posted September 23, 2007 Share Posted September 23, 2007 Then try: if ($query == "") or if ($query == null) in place of if (isset($query)) Link to comment https://forums.phpfreaks.com/topic/70233-form-submition/page/2/#findComment-353401 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.