Page 1 of 1

Submit button not working

Posted: Thu Sep 14, 2006 10:52 am
by icesolid
I have two HTML forms that submit to a PHP script. Both of the forms code are almost identical, but for some reason one of the form submit buttons require you ACTUALLY click the submit button where as the other form you can just hit enter.

FORM THAT WORKS:

Code: Select all

<form method="post" action="login.php">
<table width="275" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" height="30" colspan="2" class="topBar"><b>PLEASE LOG IN</b></td>
  </tr>
  <tr>
    <td align="center" width="120" height="35" class="greenBar"><b>Username:</b></td>
    <td align="center" width="155" class="grayBar"><input type="text" size="19" maxlength="16" name="username" class="fields"></td>
  </tr>
  <tr>
    <td align="center" height="35" class="greenBar"><b>Password:</b></td>
    <td align="center" class="grayBar"><input type="password" size="19" maxlength="16" name="password" class="fields"></td>
  </tr>
  <tr>
    <td align="center" height="35" colspan="2" class="topBar"><input type="submit" name="submit" value="Log In" class="buttons"></td>
  </tr>
</table>
</form>
FORM THAT DOES NOT WORK:

Code: Select all

<form method="post" action="override_a_case.php">
<table width="300" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" height="30" colspan="2" class="topBar"><b>ENTER A CONTROL NUMBER</b></td>
  </tr>
  <tr>
    <td align="center" class="grayBar"><br>
    <b>Control #</b> <input type="text" size="4" maxlength="6" name="control_number" class="fields">
    <br><br>
    </td>
  </tr>
  <tr>
    <td align="center" height="35" class="topBar"><input type="submit" name="search" value="Look Up Case" class="buttons"></td>
  </tr>
</table>
</form>
If I add another field to the form that does not work, the form suddenly works. Basically the problem is I can not submit just one field. Does this make sense?

Posted: Thu Sep 14, 2006 1:37 pm
by satheshf12000
hey both the forms are working when i press the enter key. i jus tried it out jus by copying your code..

Posted: Thu Sep 14, 2006 2:24 pm
by RobertGonzalez
This is a browser/HTML feature. If you are in a text form field and hit the enter key, it should submit. Same when you tab to the submit button and hit enter. Have you tested your issue in different browsers and under different circumstances.

Yes

Posted: Mon Sep 18, 2006 8:43 am
by icesolid
I have tried it many different ways and what I found was that if I have one text field and try to hit the enter key it does not work, but if i have two text fields and hit the enter key it works. Clicking the submit button always works, its when I try to hit enter it only works with two text inputs.

Posted: Mon Sep 18, 2006 10:34 am
by RobertGonzalez
Which HTML DTD are you using? And have you read up on how that DTD handles forms (or if that is even an issue)? It just seems like odd behavior.

Posted: Mon Sep 18, 2006 10:39 am
by icesolid
This is my DTD

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

Posted: Mon Sep 18, 2006 11:27 am
by RobertGonzalez
And is this happening locally, on a hosted server or both?

Posted: Mon Sep 18, 2006 11:38 am
by icesolid
On a hosted server. Why?

Posted: Mon Sep 18, 2006 12:18 pm
by RobertGonzalez
I am thinking about potential differences in the server, although this is all client side so that would probably be no issue at all.

How about browsers, have you tested it in the big four: IE, Firefox, Opera and Safari?

Posted: Mon Sep 18, 2006 12:38 pm
by icesolid
Yes. Mozilla Firefox does work, IE does not.

I know it is a really funny error and I have only encountered it once ever (on this project) and it only seems to be when I am only submitting one text field, if i submit two text fields everything works fine. I even thought it may be my HTML and CSS code, but when I remove all of my HTML and CSS code from the form it still does not work.

NEW CODE:

Code: Select all

<form method="post" action="override_a_case.php">
<input type="text" size="4" maxlength="6" name="control_number">
<input type="submit" name="search" value="Look Up Case">
</form>

Posted: Mon Sep 18, 2006 1:03 pm
by RobertGonzalez
Maybe its an IE bug. Not sure if IE has ever had a bug :wink: but it is possible.

Posted: Mon Sep 18, 2006 1:13 pm
by icesolid
That sucks. It is very agervating for the people at this company who over ride 300 cases a day and have to enter the number and click the button when they cna easily just hit submit (the way it should work).

Oh well thanks for the help!

Posted: Mon Oct 02, 2006 3:22 am
by cometfish
Hi, I had the same problem, found a solution in another forum:

http://www.phpbuilder.com/board/showthr ... nextnewest

The problem isn't that the form doesnt submit, it just doesnt send the submit button value. So if you add <input type="hidden" name="submit" value="true"> and test for $_POST['submit'] it will work.
Chances are your two different forms are testing different values - the one that's not working is testing the submit name button, the one that is, is testing a different input :)

Hope this helps someone :)
cometfish

Posted: Fri Oct 06, 2006 2:46 am
by RobertGonzalez
Have you tried giving your forms unique id's? Something like

Code: Select all

<form id="form1" action="formprocess.php" method="post">
<!-- form elements here -->
</form>

Code: Select all

<form id="form2" action="formprocess.php" method="post">
<!-- form elements here -->
</form>

Posted: Fri Oct 06, 2006 2:22 pm
by icesolid
Yes I have tried that.

cometfish's reply helped my problem. Thank you.