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
submit
Moderator: General Moderators
what does your code look like? this code worked fine:
It submitted "test" every time for submit, no matter what was pressed.
Code: Select all
<?php
if(isset($_POSTї'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>here's my code:
Code: Select all
if(isset($submit)){
print("Hello");
}else{
print("<form action="$PHP_SELF" method="get">");
print("<input type="text" />");
print("<input type="submit" name="submit" value="submit" />");
print("</form>");
}- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
and then test whether $_POST['action'] has been set in order to determine if the form has been submitted or not.
Mac
Code: Select all
<input type="hidden" name="action" value="submit" />Mac