Page 1 of 1

submit

Posted: Mon Jul 08, 2002 3:45 pm
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

Posted: Mon Jul 08, 2002 6:10 pm
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.

Posted: Mon Jul 08, 2002 10:22 pm
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;

Posted: Mon Jul 08, 2002 10:36 pm
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 )

Posted: Mon Jul 08, 2002 10:48 pm
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.

Posted: Mon Jul 08, 2002 10:59 pm
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

Posted: Tue Jul 09, 2002 1:52 am
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