[SOLVED] forms clearing when hitting enter

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

[SOLVED] forms clearing when hitting enter

Post 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?
Last edited by irealms on Thu Nov 04, 2004 4:27 am, edited 1 time in total.
DepecheM
Forum Newbie
Posts: 2
Joined: Sat Oct 16, 2004 6:31 pm

Post by DepecheM »

I think you cann't have two forms! you must have one sumbit,and one clear!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

show us code
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post 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
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

Try changing your method to "get". Be sure to handle the right array when searching. ($_POST or $_GET)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

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

?>
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

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

:?
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post 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.
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

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