Jump to content

PHP and form submition with enter button


elmas156

Recommended Posts

Hello everyone,

 

I have a page with a short form with just a password field and a submit button.  I also have php code setting variables depending on whether or not the password is correct.  When the password is entered and the submit button is CLICKED, everything works as it should.  However, when the password is entered and the ENTER button is pushed to submit the form, the form is reset and nothing else happens.  Also, this only happens in I.E., it works fine with Firefox.  I have plenty of other forms that I use in the same manner but they all work whether the submit button is clicked or the enter button is pushed to submit, regardless of what browser is used.  The idea is to have this window close (it's opened as a pop-up) and the main window load the next page.  Again, it works perfectly as long as the submit button is clicked but not if the enter button is pushed.  Not sure if it has something to do with my php code or what.  Any ideas on how to fix this?

 

Here's my code:

<?php

if (isset($_POST['submit'])) {

$pword = md5($_POST['pword']);

$q = mysql_query("SELECT * FROM `accounts` WHERE acct_number = '$acct' AND pword = '$pword'") or die (mysql_error());
$r = mysql_num_rows($q); // Checks to see if anything is in the db.

if ($r == 1) {

	$student = "true";

} else {

	$student = "false";

}

} else {

$student = "unknown";

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Student Verification...</title>
</head>

<!-- <body> tag is in PHP -->

<?php

if ($student == "true") {

echo "<body onunload=\"opener.location=('signup.php?acct1=$acct')\">";

} else {

echo "<body>";

}

if ($student == "true") {

	echo "<div align='center'>";
	echo "<p><font size='+2'>Passcode Correct!</font></p>";
	echo "</div>";
	echo "<div align='justify'>";
	echo "<p>You will now be directed to the signup page.</p>";
	echo "</div>";
	echo "<div align='center'>";
	echo "<p>Thank you.</p>";
	echo "<input type='button' value='Continue to Signup...' onClick='window.close()'>";
	echo "</div>";

	echo "<meta http-equiv=\"REFRESH\" content=\"20;url=close.php\">";

} elseif ($student == "unknown") {

echo "<div align='center'>";
	echo "<table width='325' height='175' border='0' cellspacing='0' cellpadding='0'>";
		echo "<tr>";
			echo "<td width='325' align='center' valign='middle'>";
				echo "<p><font size='+1'><strong>Welcome!</strong></font></p>";
				echo "<p>Please enter the school passcode.</p>";
				echo "<form name='form' method='POST' action='schoolpw.php'>";
				echo "<p><input type='password' name='pword' size='30' maxlength='20' /></p>";
				echo "<input type='submit' name='submit' id='submit' value='Submit' />     ";
				echo "<input type='button' name='cancel' value='Cancel' onClick='window.close()' />";
				echo "</form>";
				echo "</p>";
			echo "</td>";
		echo "</tr>";
	echo "</table>";
echo "</div>";

} elseif ($student == "false") {

echo "<div align='center'>";
	echo "<table width='325' height='175' border='0' cellspacing='0' cellpadding='0'>";
		echo "<tr>";
			echo "<td width='325' align='center' valign='middle'>";
				echo "<p><font size='+1'><strong>Welcome!</strong></font></p>";
				echo "<p><font color='#FF0000'>Incorrect Passcode! Please try again.</font></p>";
				echo "<form name='form' method='POST' action='schoolpw.php'>";
				echo "<p><input type='password' name='pword' size='30' maxlength='20' /></p>";
				echo "<input type='submit' name='submit' value='Submit' />     ";
				echo "<input type='button' name='cancel' value='Cancel' onClick='window.close()' />";
				echo "</form>";
				echo "</p>";
			echo "</td>";
		echo "</tr>";
	echo "</table>";
echo "</div>";

}

?>

</body>
</html>

Link to comment
Share on other sites

That works! 2 hours of trying everything I could think of, and I come to PHPFreaks.com and my problem is solved in less than 5 minutes!  Wow!  THANK YOU SIR... AGAIN!

 

Is this just one of those IE things, or is there a good reason that this works the way it does?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.