Page 1 of 1

HTML form within static page issue

Posted: Thu Jan 12, 2012 3:09 am
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.

Re: HTML form within static page issue

Posted: Thu Jan 12, 2012 11:10 am
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

Re: HTML form within static page issue

Posted: Thu Jan 12, 2012 11:11 am
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 ?

Re: HTML form within static page issue

Posted: Thu Jan 12, 2012 6:43 pm
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).

Re: HTML form within static page issue

Posted: Fri Jan 13, 2012 4:37 pm
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.

Re: HTML form within static page issue

Posted: Fri Jan 13, 2012 8:09 pm
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!