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?
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.
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.
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.
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.
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=
Text input fields will be sent empty, but for radio buttons and check boxes only selected items will be transmitted to the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With