Page 1 of 1

[SOLVED] forms clearing when hitting enter

Posted: Wed Nov 03, 2004 4:53 am
by irealms
I have 2 forms on a site that when i hit enter clears the field and doesnt submit, any ideas what would cause this?

Posted: Wed Nov 03, 2004 5:36 am
by DepecheM
I think you cann't have two forms! you must have one sumbit,and one clear!

Posted: Wed Nov 03, 2004 6:03 am
by John Cartwright
show us code

Posted: Wed Nov 03, 2004 9:19 am
by irealms

Code: Select all

<?php
echo '<form method="post" action="index.php?page=ordersearch">';
echo '<table cellspacing="2" cellpadding="5" bgcolor="#000000" align="center">';
echo '<tr bgcolor="#FFFFFF">';
echo '<td><b>Enter order number</b></td><td><input type"text" name="search" size="10"></td>';
echo '</tr>';
echo '<tr bgcolor="#FFFFFF">';
echo '<td colspan="2">';
echo '<input type="submit" name="searchorders" value="search">';
echo '</td>';
echo '</tr></table>';
echo '</form>';
?>
only active form on the page

Posted: Wed Nov 03, 2004 10:03 am
by wwwapu
Try changing your method to "get". Be sure to handle the right array when searching. ($_POST or $_GET)

Posted: Thu Nov 04, 2004 3:20 am
by phpScott
if you want two forms on a page that is fine but use buttons with an onClick event instead of the submit button.
The onClick event can be a simple as onClick="document.formName.submit()"
to distinguish which form to submit on the page.

Posted: Thu Nov 04, 2004 3:54 am
by timvw
no need to do all that, just make sure each submit has a unique name


Code: Select all

&lt;form method="post"&gt;
&lt;input type="submit" name="form1" /&gt;
&lt;/form&gt;

&lt;form method="post"&gt;
&lt;input type="submit" name="form2" /&gt;
&lt;/form&gt;

Code: Select all

<?php
if (isset($_POST['form1'])) {
  // handle form1 post
} else if (isset($_POST['form2'])) {
  // handle form2 post
}

?>

Posted: Thu Nov 04, 2004 3:56 am
by irealms
erm i think i need to explain again. The form works fine if you click the submit button, just not when you hit enter. Also it is the only form on the page.

Posted: Thu Nov 04, 2004 4:19 am
by phpScott
I have no idea as just cut and pasted your code into a blank html page (saved as a php file) and it works just fine for me under both IE and firefox.

:?

Posted: Thu Nov 04, 2004 4:20 am
by irealms
hmm thanks for doing that test phpscott, i'm confused too. I've used loads of forms before and not had the problem, really can't see where it's coming from.

I've also run that test now and it works in a blank page. I changed the page variable from ordersearch to something else and it redirects, then tried it as normal.

When hitting enter it seems to direct where it should but the code that recognises that submit has been sent isn't working, i am just using.

if (isset($_POST['searchorders']))

Which works find if i hit the button myself.

Posted: Thu Nov 04, 2004 4:27 am
by irealms
hmm i've fixed it, for some reason when i made the code detect the field rather than the submit button it works. Strange but true.