submit

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
dough
Forum Newbie
Posts: 4
Joined: Mon Jul 08, 2002 3:45 pm

submit

Post by dough »

How come when one clicks submit in a php form "true" is returned for the submit var, but when one presses enter "false" is returned?
Is there a way to return "true" when "enter" is pressed?

Thank you
Doug
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

what does your code look like? this code worked fine:

Code: Select all

<?php
if(isset($_POST&#1111;'text']))
	print_r($_POST);
?>

<form action="test.php" method="post" name="test">
	<input type="text" name="text">
	<input type="submit" name="test" value="submit">
</form>
It submitted "test" every time for submit, no matter what was pressed.
dough
Forum Newbie
Posts: 4
Joined: Mon Jul 08, 2002 3:45 pm

Post by dough »

here's my code:

Code: Select all

if(isset($submit))&#123;
	print("Hello");
&#125;else&#123;
	print("<form action="$PHP_SELF" method="get">");
	print("<input type="text" />");
	print("<input type="submit" name="submit" value="submit" />");
	print("</form>");
&#125;
dough
Forum Newbie
Posts: 4
Joined: Mon Jul 08, 2002 3:45 pm

Post by dough »

llimllib wrote:what does your code look like? this code worked fine
i tried your code and this is what i got if i pressed enter:
Array ( [text] => hi )

when i clicked submit i got this:
Array ( [text] => hi [test] => submit )
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

in what browser? I tested using Mozilla 1.0 and IE 6.0. what server? That shouldn't make a difference, but for giggles, what is it?
Maybe it is the get method? try it with post, see what you get.
dough
Forum Newbie
Posts: 4
Joined: Mon Jul 08, 2002 3:45 pm

Post by dough »

IE6/Apache2.x (had same problem with 1.x)
same results with post

i've noticed if i tab over to the submit button and then press enter it works but if i stay in the text field and press enter it doesn't
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It's because submit is the name of the submit button and if you don't interact with it (click on it, tab to it and press enter) it doesn't have a value at least it the majority of browsers I tested (out of interest). Even if it does work for some browsers (Opera 6 was happy) it obviously doesn't work in all (tried it in IE5.5, Netscape 4.7 and 6.1, no go) so don't use the submit button as a way of testing if a form has been submitted. Stick a hidden field in, something like

Code: Select all

<input type="hidden" name="action" value="submit" />
and then test whether $_POST['action'] has been set in order to determine if the form has been submitted or not.

Mac
Post Reply