How to Create a Confirmation Page for an HTML Web Form Using PHP

PHP


In this article, we show how to create a confirmation page for an HTML web form using PHP.

Let's say we have the form below. Let's pretend it's a form that a company uses for its customers to elicit information from them.









However, this form doesn't do anything when the submit button is pressed. Therefore, it's useless. We neither post nor retrive the customer's information.

How can we make this form useful so that we can take the information and post a confirmation page to the user so that he/she knows that the information has been successfully received.

To do this, we use PHP.















To create this form, this is the code used, shown below, to do so:



The first line is of the most importance.

The form tag contains the "action" attribute.
The "action" attribute is set to the PHP file that will contain the script that allows us to create the confirmation page. In this case, the PHP file is customerinfo.php, but you can call your PHP file whatever you want. Just make sure it correlates to the appropriate name of the external PHP file that it references. The "method" attribute tells the server that we want to retrieve this data and post it to a web page.

All of the data below this first line is just standard HTML to create the text boxes.

Now that we know the HTML to set up for the creation of the confirmation page, let's go over what goes into the PHP file.


PHP File

This is the PHP file:

Everything in this file is standard HTML except for the code in the PHP block, which is highlighted above in red. So the code in red, the PHP code, is the only section we'll focus on.

The echo command prints out statements to the computer screen.
-The echo statement is placed in ' ' (single quotes).
0The first part of the echo statement, 'First Name: ' prints out "First Name: "
-The . (period) is a concatenation operators. It connects together the various parts of a PHP statement.
-The $_POST ["FirstName"] follows next. The "FirstName" is the variable name of the textbox that asks for the customer's first name. The $_Post must be written so that the variable can be fetched from the HTML document that contains the user-added variable. Otherwise, it would look for the variable on the same page.
-The concatenation operator again to connect the various parts of a statement. -The br tag now appears within ' ' (single quotes) to give a line break within each of the echo statements.
-The semicolon (;) ends the statement in PHP.

And this repeats for all the other variables.

And this is how a confirmation page is created for an HTML Web Form using PHP.

Related Resources

How to Create a Search Engine Using PHP

How to Upload Images to a Website Using PHP

How to Upload Files to a Website Using PHP

How to Create Your Own File Transfer Protocol (FTP) For Your Website Using PHP

How to Create a Register and Login Page Using PHP




HTML Comment Box is loading comments...