PHP form | How can we design a form in PHP

You are currently viewing PHP form | How can we design a form in PHP

PHP form | How can we design a form in PHP.

A form in web development is an interactive element that allows users to input data and submit it to a web server for processing. Forms are a fundamental part of web applications and are used for various purposes, such as user registration, login, search, data submission, and more. PHP is commonly used to design and handle forms on the server side.

Designing a Form in PHP:

The example below displays a simple HTML form(form.html) with two input fields and a submit button:

				
					html>
<body data-rsssl=1>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

				
			

Output of above code is :-

Php form

When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named “welcome.php”. The form data is sent with the HTTP POST method.
To get form data, we need to use PHP superglobals $_GET and $_POST.
The form request may be get or post. To retrieve data from get request, we need to use $_GET, for post request $_POST.
To display the submitted data we could simply echo all the variables. The “welcome.php” looks like this:

				
					<html>
<body data-rsssl=1>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>

				
			

The output could be something like this:

				
					Welcome Vishal
Your email address is codewithvishal41@gmail.com

				
			

The same result could also be achieved using the HTTP GET method.

Leave a Reply