HTML form within static page issue

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

HTML form within static page issue

Post by Don Chambers »

Ok, maybe I am getting rusty on my html, not that it was ever great...

Trying to include a form in a static page.... why does this:

Code: Select all

<form method="post" action="http://www.mysite.com/url.php?this_group=2&that_id=3">
    <input type="submit" value="hello world" />
</form>
redirect to just "http://www.mysite.com/url.php" and not the full url including attributes? ie, ?this_group=2&that_id=3. is omitted from the actual form action.... some browsers even show the full URL including ?this_group=2&that_id=3 in the browser's address bar, but the actual content displayed is just what is generated by http://www.mysite.com/url.php

Hope that made sense. Anyway, any advice appreciated.
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: HTML form within static page issue

Post by garvinhicking »

Hi!

Mixing in GET variables inside a POST form method is usually not that good. Do you have the actual URL to url.php to test this? One can use Firefox tools like LiveHTTPHeaders to check what is really transferred to the server, and in your URL.php script, certain variables might not be in the $_GET or $_POST array. Usually you can better use $_REQUEST to access variables, because then it doesn't matter if the variables came fomr a GET or POST request.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
sonichouse
Regular
Posts: 196
Joined: Sun May 11, 2008 2:53 am
Contact:

Re: HTML form within static page issue

Post by sonichouse »

Not tried this, but don't you need to create hidden text fields this_group and that_id with the respective values for them to be posted ?
Steve is occasionally blogging here
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: HTML form within static page issue

Post by Don Chambers »

After further digging, it seems that you simply cannot pass the query string via a form action and had nothing to do with it being part of a static page (I thought maybe the static page was somehow stripping away the query string). However, this worked:

Code: Select all

<form method="post" action="http://www.mysite.com/url.php">
    <input type="hidden" name="this_group" value ="2" />
    <input type="hidden" name="that_id" value="3" />
    <input type="submit" value="hello world" />
</form>
EDIT: Both method="post" and method="get" produce the correct result. Interesting to note that method="get" results in the full url with query string showing in the browser window while method="post" supresses the query string portion (though, the query string result is correct).
=Don=
onli
Regular
Posts: 2830
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: HTML form within static page issue

Post by onli »

EDIT: Both method="post" and method="get" produce the correct result. Interesting to note that method="get" results in the full url with query string showing in the browser window while method="post" supresses the query string portion (though, the query string result is correct).
Yes, that exactly is the difference. GET-params are part of the url, like index.php?param1=abc&param2=def. POST-params are written into a section below the http-request. http://developers.sun.com/mobility/midp/ttips/HTTPPost/ explains it quite well, i think.
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: HTML form within static page issue

Post by Don Chambers »

onli wrote:Yes, that exactly is the difference. GET-params are part of the url, like index.php?param1=abc&param2=def. POST-params are written into a section below the http-request. http://developers.sun.com/mobility/midp/ttips/HTTPPost/ explains it quite well, i think.
Excellent explanation - thanks!
=Don=
Post Reply