PHP

Using Hidden Field


 

In PHP, the `<input type="hidden">` is an HTML form input element used to create a hidden input field. This field is not visible to the user but can still be submitted with the form data when the form is submitted.

 

Syntax:

<input type="hidden">

 

Example(form.html):

<!DOCTYPE html>
	<html lang="en">
	<head>
    	<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<title>Hidden Input Example</title>
	</head>
	<body>
    	<form action="hiddenData.php" method="post">
        	<label for="username">Username:</label>
        	<input type="text" id="username" name="username" required>
        
	
        	<!-- Hidden input field -->
        	<input type="hidden" name="hidden_field" value="2343">

	
        	<button type="submit">Submit</button>
    	</form>
	</body>
	</html>

 

hiddenData.php

<?php
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
    	$username = $_POST["username"];
    	$hiddenValue = $_POST["hidden_field"];

	
    	echo "Your name is: " .$username;
    	echo " and your application no is: " .$hiddenValue;
	}
	?>

 

Note: The hidden input field is often used to include data that doesn't need to be displayed to the user but is needed for processing on the server side.