Submit button not working

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Submit button not working

Post 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?
satheshf12000
Forum Commoner
Posts: 25
Joined: Mon Sep 04, 2006 5:38 pm

Post by satheshf12000 »

hey both the forms are working when i press the enter key. i jus tried it out jus by copying your code..
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Yes

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

This is my DTD

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

And is this happening locally, on a hosted server or both?
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

On a hosted server. Why?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post 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>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Maybe its an IE bug. Not sure if IE has ever had a bug :wink: but it is possible.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post 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!
cometfish
Forum Newbie
Posts: 1
Joined: Mon Oct 02, 2006 3:17 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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>
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Post by icesolid »

Yes I have tried that.

cometfish's reply helped my problem. Thank you.
Post Reply