Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML forms - input type submit problem with action=URL when URL contains index.aspx

Tags:

I have a HTML form that truncates the action parameter after the "?" mark - which is NOT the desired behavior I am looking for.

Here is a representative HTML snippet:

<form action="http://spufalcons.com/index.aspx?tab=gymnastics&path=gym">
    <input type="submit" value="SPU Gymnastics"/>
</form>

In this case, the submit button takes you to the "http://www.spufalcons.com/index.aspx" page, effectively ignoring "?tab=gymnastics&path=gym" parameter. It appears that all HTML and PHP pages referenced in the action=URL work as expected. This behavior is consistent across all major browsers (IE, FF, Safari, Chrome, Opera).

Has anyone seen this problem before? Or can suggest an alternative and/or workaround consistent with my "pure" CSS/HTML/PHP web development approach? I have tried replacing the special characters with HTML entity values with no impact. I REALLY don't want to use abandon my CSS-styled submit buttons by using Javascript or button PNG's or image maps.

Environment:

  • Web Server: Apache 2.2.14
  • PHP: 5.2.10
  • OS: Mac OS X 10.5.8
  • HTML document info:
  • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

TIA -- Trent

like image 683
Trent Avatar asked Dec 29 '09 22:12

Trent


3 Answers

Put the query arguments in hidden input fields:

<form action="http://spufalcons.com/index.aspx">
    <input type="hidden" name="tab" value="gymnastics" />
    <input type="hidden" name="path" value="gym" />
    <input type="submit" value="SPU Gymnastics"/>
</form>
like image 124
Gumbo Avatar answered Oct 25 '22 23:10

Gumbo


Use method=POST then it will pass key&value.

like image 31
kunal Avatar answered Oct 25 '22 23:10

kunal


This appears to be my "preferred" solution:

<form action="www.spufalcons.com/index.aspx?tab=gymnastics&path=gym" method="post">  <div>
<input type="submit" value="Gymnastics"></div>

Sorry for the presentation format - I'm still trying to learn how to use this forum....

I do have a follow-up question. In looking at my MySQL database of URL's it appears that ~30% of the URL's will need to use this post/div wrapper approach. This leaves ~70% that cannot accept the "post" attribute. For example:

<form action="http://www.google.com" method="post">
  <div>
    <input type="submit" value="Google"/>
  </div></form>

does not work. Do you have a recommendation for how to best handle this get/post condition test. Off the top of my head I'm guessing that using PHP to evaluate the existence of the "?" character in the URL may be my best approach, although I'm not sure how to structure the HTML form to accomplish this.

Thank YOU!

like image 32
Trent Avatar answered Oct 25 '22 21:10

Trent