Form doesn't work when ENTER is hit.

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
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Form doesn't work when ENTER is hit.

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
oceglok
Forum Newbie
Posts: 5
Joined: Sun Mar 27, 2005 2:03 pm
Location: Nagoya-City, Japan

Post 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
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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.

:)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Post Reply