click submit twice ...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pepe_lepew1962
Forum Commoner
Posts: 44
Joined: Thu Nov 20, 2008 10:29 am

click submit twice ...

Post by pepe_lepew1962 »

Hi:

I need help figuring this out. For some reason I have to click the submit button TWICE instead of once before it continues to the next form.

Thanks,


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
<style>
.errText
{
font-family: Arial;
font-size: 10px;
color: #CC0000;
text-decoration: none;
font-weight: normal;
}
</style>

<title>Verification !!!</title>
</head>
<?php
$errFName = "";
$errMName = "";
$errLName = "";
$frmCounter = 0;

if($_POST["ac"]=="login")
{
// If First Name is NOT letters, dash or spaces then display error message.
if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["fname"]) === 0)
$errFName = '<class="errText">First name must be from letters, dashes, spaces and must not start with dash';
else
$frmCounter = $frmCounter + 1;
// Add validation & Santization here
// If Middle Name is NOT letters, dash and spaces then display error message.
if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["mname"]) === 0)
$errMName = '<class="errText">Middle name must be from letters, dashes, spaces and must not start with dash';
else
$frmCounter = $frmCounter + 1;
// Add validation & Santization here
// If Middle Name is NOT letters, dash and spaces then display error message.
if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["lname"]) === 0)
$errLName = '<class="errText">Last name must be from letters, dashes, spaces and must not start with dash';
else
$frmCounter = $frmCounter + 1;
// Add validation & Santization here
//
if ($frmCounter == 3)
{
$frmSubmit = "connecter.php";
}
else
{
$frmSubmit = $_SERVER['$PHP_SELF'];
}
}
?>

<body>

<form name="main" action="<?php echo $frmSubmit; ?>" method="POST">
<input type="hidden" name="ac" value="login">
<table border="1" width="100%">
<tr>
<td width="124">&nbsp;</td>
<td width="278">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="124" bgcolor="#FFFFFF">
<b><font size="2" face="Arial" color="#3366FF">&nbsp; First Name:</font></b></td>
<td bgcolor="#FFFFFF">
<b><font size="2" face="Arial" color="#FF0000">&nbsp;</font></b>
<input name="fname" style="Width: 262; height:22" maxLength="15" size="2" value="<?php echo $_POST['fname']; ?>" ></td>
<td>&nbsp;<?php if(isset($errFName)) echo $errFName; ?></td>
</tr>
<tr>
<td width="124" bgcolor="#FFFFFF">
<b><font size="2" face="Arial" color="#3366FF">&nbsp; Middle Name:</font></b></td>
<td bgcolor="#FFFFFF">
<b><font size="2" face="Arial" color="#FF0000">&nbsp;</font></b>
<input name="mname" style="Width: 98; height:22" maxLength="15" size="2" value="<?php echo $_POST['mname']; ?>" ></td>
<td>&nbsp;<?php if(isset($errMName)) echo $errMName; ?></td>
</tr>
<tr>
<td width="124" bgcolor="#FFFFFF">
<b><font size="2" face="Arial" color="#3366FF">&nbsp; Last Name:</font></b></td>
<td bgcolor="#FFFFFF">
<b><font size="2" face="Arial" color="#FF0000">&nbsp;</font></b>
<input name="lname" style="Width: 98; height:22" maxLength="25" size="2" value="<?php echo $_POST["lname"]; ?>" ></td>
<td>&nbsp;<?php if(isset($errLName)) echo $errLName; ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: click submit twice ...

Post by andym01480 »

Of course you will have to submit twice!

The first submit post back to itself because $frmSubmit is not set. If everything is valid (which it wont be because of another error) the form is reprinted with the action="connector.php", requiring a second submit to post the valid data to connector.php - trouble is someone could re-enter with invalid data at that point which wouldn't be validated!!!

The other error is

Code: Select all

if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["lname"]) === 0)
should be

Code: Select all

if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["lname"]))
for each of the three.

You need to rewrite your code - perhaps a header redirect with session variables or get variables. But you'll need to move the html down below where the rest of the form is. But you would still need to validate the data when it arrives at connector.php!!!
Post Reply