Page 1 of 1

Form doesn't work when ENTER is hit.

Posted: Sat Mar 26, 2005 10:43 am
by Dale
I have a form which deletes from the database whena password is entered. However when i "click" the button with my mouse, it works. However when I hit "ENTER" the form doesn't work and it just seems to refresh the page.

Heres my form code piece:

Code: Select all

*snip*
<tr>
<td class=&quote;trow1&quote; align=&quote;left&quote; colspan=&quote;2&quote;><form action=&quote;&quote; method=&quote;POST&quote; name=&quote;deleteab&quote;>Are you sure you want to delete this? If so, enter your password below and hit the &quote;Confirm Delete&quote; button.<br><font color=&quote;#FF0000&quote;><b>WARNING:</b> This action cannot be reversed!</font><br>Enter Your Password:<br><input type=&quote;password&quote; name=&quote;g_del_password&quote; size=&quote;50&quote;><br><input type=&quote;submit&quote; name=&quote;deleteab&quote; value=&quote;Confirm Delete&quote;></form></td>
</tr>
*snip*
... and heres some more code from the top of the page:

Code: Select all

<?php
if(isset( $deletegb ))
{
	$gbdelpass82 = $_POST['g_del_password'];
	$gbdelpass82 = md5($gbdelpass82);

	$conn = mysql_connect("localhost","***","***");
	mysql_select_db("***",$conn) or die(mysql_error());

	$sql = "SELECT * FROM users WHERE password = '$gbdelpass82' AND uid = $gad[uid]";
	$result = mysql_query($sql,$conn) or die(mysql_error());
	while ($r = mysql_fetch_array($result)) {
		$g_password_d = $r['password'];
	}

	if ($gbdelpass82 == $g_password_d) {
		*snips out the delete thingy*
		echo "<a href=\"./ser.php\">Done</a>";
	} else {
		echo "Problem";
	}
exit;
}
?>
Could you tell me why this happens?

Posted: Sat Mar 26, 2005 11:03 am
by onion2k
Hitting enter is NOT the same as clicking a submit button. If you're relying on $_POST['mysubmitbuttonname'] being set, you'll be disappointed.

Posted: Sat Mar 26, 2005 11:10 am
by Dale
onion2k wrote:Hitting enter is NOT the same as clicking a submit button. If you're relying on $_POST['mysubmitbuttonname'] being set, you'll be disappointed.

Ohhh... so what do i use that will work with clicking AND enter'ing?

Posted: Sat Mar 26, 2005 11:12 am
by feyd
$_SERVER['REQUEST_METHOD'] :)

Your code looks like it relys on register_globals being on as well.. be careful with this as there are security concerns and compatibility issues you could hit if and when your host upgrades to a newer version of php.

Posted: Sun Mar 27, 2005 2:28 pm
by oceglok
I usually put a hidden field in my forms and check on it first:

Code: Select all

if (isset($_REQUEST['myhiddenfield']) and
      $_REQUEST['myhiddenfield'] == "myvalue") {
    // user pressed the Enter key
}
Hope, this helps
oceglok

Posted: Sun Mar 27, 2005 2:38 pm
by Dale
oceglok wrote:I usually put a hidden field in my forms and check on it first:

Code: Select all

if (isset($_REQUEST['myhiddenfield']) and
      $_REQUEST['myhiddenfield'] == "myvalue") {
    // user pressed the Enter key
}
Hope, this helps
oceglok
Cheers! I'll try and see if i can use this.

:)

Posted: Sun Mar 27, 2005 2:43 pm
by John Cartwright
should change $_REQUEST to $_POST or $_GET depending on your form action.
If you know its coming from a form (with action = POST) then use $_POST instead of $_REQUEST, and visa versa.