Reputation: 549
I'm echoing out a form that uses the method GET to send material via several input type="hidden". Like this:
echo '
<form action="somewhere.php" method="GET" name="whatever" id="whatever">
<input type="hidden" name="get_method" value=" . '$foo' . ">
<input type="hidden" name="want_to_send_with_post" value=" . '$my_post' . ">
</form>
';
This works fine, but how do I send one of these input types as POST, since it's the form that determines the method? Is there a way that an individual input type can override the form method? I know that an input button can override the form method (see here), but that's creating a separate entity. I want to send both GET and Post simultaneously.
The reason: I want to send category names with Get and a text message with POST.
Upvotes: 1
Views: 324
Reputation: 572
Yeah, you can! Specify the GET data in the URL you're heading to.
(I would edit the GET info with javascript as the user inputs their data)
<input type="text" id="get"> <!--user types get stuff here-->
<form action="somewhere.php?get=something" method="POST" id="form">
<input type="hidden" name="post" value="<?= $mypost ?>" />
</form>
Use JS to change the GET action
var form = doc.getId("form")
var get = doc.getId("get").onkeyup = updateLoc;
function updateLoc() {
form.action = "somewhere.php?get=" + get.value;
}
Then PHP can deal with $_POST["post"]
and $_GET["get"]
separately.
Upvotes: 1