Checking input in form before continue...<

liunx

Guest
Hi All,

I have a form with a submit button...

Could someone tell me how I can check that something has been entered in the form before I allow them to submit... like if they havn't entered a name then it takes them to a page that says "You havn't filled in the following... name, whateva else <click here> to go back and correct it"

Thanks for any help,

Mike

Also is there a way to go back to previous page using php?
Not a link to the previous page (will not have whatever input they did enter) but a link that will simulate the "back" button on the browserDo something like:
<form name="form_name" id="" method="post" action="php_handler_file.php">
<input name="name" type="text" id="name" />
</form>
Then in php_handler_file.php you need to do this:

//check if the "name" field that was posted is empty
if($_POST['name'] == "")
{
<What to do if not filled in goes here>
}

As far as I know, there is no way to simulate the back button with php. I use javascript like this:

<script type="text/javascript" language="javascript">
setTimeout("history.go(-1)",5000);
</script>
That will forward them back after 5000 milliseconds (or 5 seconds). So I combine php & js, and use php to echo a little message, and the js from inside the if statement.
The php_handler_file.php might start with something like this:

if ($_POST['name'] == "")
{
echo "<div style=\"text-align:center;\">You forgot to fill in your name.<br />"
."You will be sent back the form now.<br />"
."If you do not get forwarded, hit your back button to redo it.</div>"
."<script type=\"text/javascript\" language=\"javascript\">"
."setTimeout(\"history.go(-1)\",5000);</script>";
exit;
}With that code you gave me to return to previous page using javascript... could that be converted into a link rather then a timeout thing?

Thanks,
MikeOriginally posted by HinkWaS
With that code you gave me to return to previous page using javascript... could that be converted into a link rather then a timeout thing?

Thanks,
Mike

try:

<a href=http://www.htmlforums.com/archive/index.php/"#" onclick="javascript:history.go(-1)">click</a>yep, just make sure there is no space between java and script. This board seems to insert one.That looks good but I get an error...
I have

print("<center><h3><a href=http://www.htmlforums.com/archive/index.php/"#" onclick="javascript:history.go(-1)">Click here</a> to return to the form.</h3></center><hr>");


It seems to not like # as everything after # seems to be 'commented out' so to speak... (it all goes light yellow after # till the end of the line)

Thanks,
MikeYou need to escape your quotes with slashes or use single quotes.

Look at the php syntax highlighting.Ok its working as I wanted it to...

Thanks to all that replied!!!
 
Back
Top