I'm using node.js with Express. I have a page /blah?name=john which produces a page with a form. When you click the form submit button it passes the form data to a POST request. However I want part of the post request to be whatever the ?name=john
data was from the GET request that produced the page. How can I forward the name variable along with the submitted form data to a POST request?
Dynamically add the query string to some hidden input. So that your form will look like:
<form action="/submit" method="post">
<input type="text" placeholder="Some text here">
<!-- Hidden input -->
<input type="hidden" name="name" value="john">
<input type="submit" value="submit">
</form>
You should generate on the server this hidden input depending on the GET parameters :)
During the GET request, set the ACTION on your form to "MyPostPage.htm" + query_string. When the form is posted via the submit button, it will use the form's ACTION attribute which has the added query string information from the initial GET request.
<HTML>
<FORM ACTION="http://example.microsoft.com/sample.asp?name='fred'&age=27" METHOD="POST">
Enter your name: <INPUT NAME="FName"><BR>
Favorite Ice Cream Flavor:
<SELECT NAME="Flavor">
<OPTION VALUE="Chocolate">Chocolate
<OPTION VALUE="Strawberry">Strawberry
<OPTION VALUE="Vanilla" SELECTED>Vanilla
</SELECT>
<P><INPUT TYPE=SUBMIT>
</FORM>
</HTML>