Search code examples
htmlformspostnullsend

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?


Solution

  • 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=