Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty form POST data

Can anybody tell me what happens if you are sending an HTML form via POST and you don't enter data?

For example: an input field "name" sent via POST to another page (e.g servlet or PHP). What does the receiving page get if you don't enter a value? Is the element not sent (null) or do you get the empty string?

like image 342
J-H Avatar asked Sep 15 '12 11:09

J-H


People also ask

How do you post data from a form?

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.

How do you clear a form in HTML?

You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.

What is a post form HTML?

HTML HTTP Media Types. A method="post" attribute value specifies that the form data will be sent to the server by storing it in an HTTP request body. This method is used to transfer data securely using HTTP headers.

What is form method post in PHP?

PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables. The example below shows a form with an input field and a submit button.


2 Answers

Empty Value is what you will receive. In your words (""), considering there is no validation and the form is submitted.

Just out of curiosity, are you implementing validation on the server side for empty values? I recommend you to first check for empty values on the client before submitting the form. This way your UI will be seamless and you will save bandwidth.

This is how the POST request will look like with non-empty values:

POST /submitpage.php HTTP/1.1
Host: www.awebsite.com
User-Agent: Safari/4.0
Content-Length: 39
Content-Type: application/x-www-form-urlencoded  

name=Ashwin+Singh&age=21&job=Developer

With empty values passed it will look like this:

POST /submitpage.php HTTP/1.1
Host: www.awebsite.com
User-Agent: Safari/4.0
Content-Length: 16
Content-Type: application/x-www-form-urlencoded

name=&age=&job=
like image 119
Ashwin Singh Avatar answered Sep 22 '22 23:09

Ashwin Singh


Text input fields will be sent empty, but for radio buttons and check boxes only selected items will be transmitted to the server.

like image 36
knittl Avatar answered Sep 23 '22 23:09

knittl