PHP Beginners

How to get hidden input field values in PHP?

To get hidden input field values in PHP, we use PHP global variable, To create a hidden field, we create an HTML...

Written by Bikash · 53 sec read >

To get hidden input field values in PHP, we use PHP global variable,

  1. $_POST
  2. $_REQUEST

To create a hidden field, we create an HTML input field with type="hidden" and to store data inside the input field we have to use value="anyValue" attribute.

How to get data from the hidden fields in PHP?
Get hidden input field values in PHP

In the above code, we are using name the attribute which is used to get the input value by using PHP POST and REQUEST methods.

Also Read: User Login Form Validation using Ajax in PHP

Example To Get values From The Hidden Fields in PHP

Output:

your_hidden_value
PHPCODER

Also Read: PHP CRUD Operation Using MySQLi (Source Code)

Code Highlights:

In the above code, first, we create an HTML form with the method POST and action attribute for form submission.

Then we create 3 input fields,

  • hidden input
  • text input
  • submit button input

All inputs have their name attribute. Remember name attribute is important to send the data to the PHP code.

Now, we write the PHP code to get the data,

First, we check whether the button is clicked or not by using the PHP isset() method, where we pass the submit button value as a parameter.

Then by using $_POST the method we take hidden field and text field data.

I hope you get all the things. To know more, you can check here as well https://www.w3schools.com/tags/att_input_type_hidden.asp

Happy coding..!

Was this article helpful?
YesNo
Written by Bikash
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP. Profile

Leave a Reply

Your email address will not be published. Required fields are marked *