PDA

View Full Version : submit button on click only?


AthroughZ
01-28-2010, 12:07 AM
I have a form that when you hit submit it inserts the info into a database and then send an email containing the info to someone. That all works great. The problem is the user hits the enter key instead of the tab to go to the next field so the form is submitted before it's complete. Not all info is required so if the required info is complete and they hit the enter key by mistake it goes. What is the best way to stop this from happening? Is there a way to make the user have to click on the button instead of hitting the enter key? Any ideas would be appreciated.

rattlsnak
01-28-2010, 01:57 AM
post the form code.

gentleone
01-28-2010, 05:03 AM
You have to integrate a required form fields script or even a better validation script that checks more that that. There are many that you can find on the net, but it depends on how you've setup your form. So a code for us to see would indeed be handy.

tux
01-29-2010, 08:21 AM
Gentleone and Rattlsnak are right we could help you more if we see your code.

Here is a very basic form validation script using PHP to give you an idea.

<?php

$firstname = $_POST['firstname']; //
$lastname = $_POST['lastname']; // delcare your vars here from your form
$email = $_POST['email']; //

if($firstname && $lastname && $email){ // this looks to see if each field contains a value
$result = "Your form was sent successfully!!"; // prints success message

}else $result = "All fields are required!!"; // if a field is empty prints an error message

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<p><?php echo $result; ?></p>

<form name="form1" method="post" action="">
<p>Fistname
<input type="text" name="firstname" id="firstname">
</p>
<p>Lastname
<input type="text" name="lastname" id="lastname">
</p>
<p>Email
<input type="text" name="email" id="email">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

</body>
</html>
//your code here to INSERT to DB and send email here
}else $result = "All fields are required!!";

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<p><?php echo $result; ?></p>

<form name="form1" method="post" action="">
<p>Fistname
<input type="text" name="firstname" id="firstname">
</p>
<p>Lastname
<input type="text" name="lastname" id="lastname">
</p>
<p>Email
<input type="text" name="email" id="email">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

</body>
</html>

Hope this helps.

Regards Paul