To get hidden input field values in PHP, we use PHP global variable,
- $_POST
- $_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.
1 |
<input type="hidden" name="hiddenFieldName" value="what_ever" /> |

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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<form method="post" action="<?php print $_SERVER ['PHP_SELF']?>"> <input type="hidden" name="hiddenField" value="your_hidden_value" /> Non Hidden Field: <input type="text" name="nonHidden" value="PHPCODER" /> <input type="submit" name="submitForm" value="submit"> </form> <?php // here we check button is clicked or not if(isset($_POST['submitForm'])){ //print hidden field value echo $_POST['hiddenField']; //print normal text or non hidden field value echo $_POST['nonHidden']; } ?> |
Output:
your_hidden_value
PHPCODER
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..!