Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a Header field on POST a form?

How can I set a custom field in POST header on submit a form?

like image 394
Reza Owliaei Avatar asked Mar 01 '12 13:03

Reza Owliaei


People also ask

How do I POST a header in a form?

However you may use for example jquery (although you can do it with plain javascript) to serialize the form and send (using AJAX) while adding your custom header. Look at the jquery serialize which changes an HTML FORM into form-url-encoded values ready for POST.

How to pass form data in POST request?

To post HTML form data to the server in URL-encoded format, you need to make an HTTP POST request to the server and provide the HTML form data in the body of the POST message. You also need to specify the data type using the Content-Type: application/x-www-form-urlencoded request header.


2 Answers

It cannot be done - AFAIK.

However you may use for example jquery (although you can do it with plain javascript) to serialize the form and send (using AJAX) while adding your custom header.

Look at the jquery serialize which changes an HTML FORM into form-url-encoded values ready for POST.

UPDATE

My suggestion is to include either

  • a hidden form element
  • a query string parameter
like image 118
Aliostad Avatar answered Sep 20 '22 12:09

Aliostad


Set a cookie value on the page, and then read it back server side.

You won't be able to set a specific header, but the value will be accessible in the headers section and not the content body.

like image 24
Chris Hynes Avatar answered Sep 18 '22 12:09

Chris Hynes