GET+POST in same form?
October 26, 2006 9:02 AM Subscribe
Is it possible to set the
For example, I'd like the following code:
to return GET value containing
Is this reasonable or possible?
action
attribute of an HTML form, such that the method
is POST
, but the action
includes GET variables?For example, I'd like the following code:
<form name="edit_name" action=".?debug" method="post">
<input type="submit" value="Edit">
</form>
to return GET value containing
debug
and a POST value containing Edit
.Is this reasonable or possible?
Response by poster: Doesn't seem to work, even with a fully-specified path in the action. Only the GET variable gets through; POST is empty. I'm using PHP.
posted by Blazecock Pileon at 9:13 AM on October 26, 2006
posted by Blazecock Pileon at 9:13 AM on October 26, 2006
Best answer: Yeah, the HTML you posted isn't quite right.
Try this:
The problem was your input button didn't have a name attribute. Now, after clicking edit, your PHP $_GET superglobal should contain the 'debug' field, with no value, and $_POST will contain the 'myfield' field, with value 'Edit'.
posted by matthewr at 9:20 AM on October 26, 2006
Try this:
<form name="edit_name" action="this.php?debug" method="post">
<input type="submit" name="myfield" value="Edit">
</form>
The problem was your input button didn't have a name attribute. Now, after clicking edit, your PHP $_GET superglobal should contain the 'debug' field, with no value, and $_POST will contain the 'myfield' field, with value 'Edit'.
posted by matthewr at 9:20 AM on October 26, 2006
Response by poster: I'm a dummy; thanks so much.
posted by Blazecock Pileon at 9:24 AM on October 26, 2006
posted by Blazecock Pileon at 9:24 AM on October 26, 2006
Out of curiosity, why would you want to mix GET and POST? Wouldn't it be easier (and less hacky) to just use POST for all the variables?
<input type="hidden" name="debug" value="whatever">
posted by ook at 9:26 AM on October 26, 2006
<input type="hidden" name="debug" value="whatever">
posted by ook at 9:26 AM on October 26, 2006
Response by poster: I'd like to be able to debug variables "on the fly" as I write methods, whether or not I've triggered a form.
posted by Blazecock Pileon at 9:47 AM on October 26, 2006
posted by Blazecock Pileon at 9:47 AM on October 26, 2006
That syntax won’t work, though; you’ll need to give the path to the page, which probably isn’t a single dot.
You can also get away with just
The browser (well, Firefox and IE, at least) will construct the URI appropriately, saving you a little URL munging.
posted by IshmaelGraves at 11:06 AM on October 26, 2006
You can also get away with just
?foo=bar
bit:<form name="edit_name" action="?debug" method="post">
The browser (well, Firefox and IE, at least) will construct the URI appropriately, saving you a little URL munging.
posted by IshmaelGraves at 11:06 AM on October 26, 2006
FWIW you can also do "./?blahblahblah" if you want to be both explicit ("I want to access the same URL/resource that I'm currently at") and terse.
posted by cyrusdogstar at 2:44 PM on October 26, 2006
posted by cyrusdogstar at 2:44 PM on October 26, 2006
This thread is closed to new comments.
If you’re using something proprietary as a server-side language, they may not have support for it, because it’s not really idiomatic. PHP and Perl certainly do, and I would be shocked if Ruby and Python didn’t. But that wasn’t your question :-) .
posted by Aidan Kehoe at 9:10 AM on October 26, 2006