Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Once you've created a working data entry form, you can then handle your form submissions with a little bit of PHP code. For this demonstration, I'll use the file simpleform2.php. It has a copy of the form that I created in a previous video. The first step is to remember what the names of your form controls are. When I created this form, I created two text controls. The first one had a name and ID of firstname. You'll need to remember those values in order to handle your PHP form submission.
To make this easy to code, I'll use the Bindings panel. The Bindings panel lets you set up form and other types of variables that you can then easily insert into your PHP code. I'll go to the Plus button, and I'll choose Form Variable. I'll set a Form Variable name of firstname, matching the name and ID of the first form control, and I'll click OK. Then I'll repeat the process to create a Form Variable for lastname.
By placing these items in the Bindings panel, you're not actually changing the page yet; you're just creating a bit of reusable code that you can add to your page as you need to. Next, I'll look at the page in Code View, and I'll go to the top of the page. The first time the page is viewed, I'm only going to see the data entry form, but the second time the page is viewed after the form has been submitted, I want to get the values that the user typed into the form and display them on the screen. I need a little bit of PHP conditional code to do that.
I'll place the cursor after the body tag, and before the form, and make a little bit of space. Then I'll add a PHP code block. I'll go to the Insert panel to the PHP category, and I'll click on Code Block. Then I'll make a little bit of extra space inside the code block. Next, I'm going to ask the question, has the form been submitted? You can do this by checking for a particular variable, and asking whether it's set yet. The particular variable I'm interested in is the firstname variable.
Even if the user doesn't type anything into it, it will still create a form variable when the form is submitted. I'll use a PHP conditional statement, if, and then I'll put in a pair of parentheses, and then a pair of braces. Within the pair of parentheses, I'll use the isset function, and once again a pair of parentheses. I'm going to add the reference to the firstname form variable between the parentheses. Before I do this, I'm going down to the Properties panel, and I'll click Refresh, or press F5.
This causes Dreamweaver to read the page that I've just hand-coded, and it will give it the context to correctly add the PHP code I want. Next, I'll go to the Bindings panel, I'll locate my firstname variable, and I'll drag it and place it between the parentheses of the isset function. So, now I'm asking the question, does this variable exist? And if it does exist, I want to output this and the other variable to the screen. So, now I'll place the cursor between the curly braces, and I'll use the echo command a number of times to output some information.
I'll say echo, and then the word "Welcome," comma, space, I'll make sure to end that statement with a semicolon. I'll type the word "echo" again. Once again, I'll refresh before I use the Bindings panel. I'll go to the Bindings panel and drag in the firstname. Then I'll put in a dot. In PHP, that means I'm going to append, or add a value after that. Then I'll put in a space wrapped in quotes, and another dot. I'll once again refresh, go to the Bindings panel and drag in the lastname, and I'll close that statement with a semicolon.
Finally, I'll add one more echo command, and explicitly add a break tag, or br tag, to cause a line feed at the end of this line. So now, I'm handling and outputting the values that are submitted from the form, but I'm only doing this if the form was submitted already and this is the second time I'm viewing the page. I'll save my changes, and I'll test the page in an external browser. When the form opens, I'll click into the first control, and I'll type Davey Jones.
I'll click Submit, and when the form is submitted, I see the response, Welcome, Davey Jones. This response is created by the echo commands within the conditional code that's placed above the form. So, that's a look at the basics of how data entry forms work, and how you process them with PHP code. If your form was set up with a method of post, your variables will appear like this: dollar underscore POST, bracket, then the name of the form control, wrapped in quotes, close bracket.
And you can check to see whether the variable exists at any point by wrapping it in the PHP isset function.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97680 Viewers
80 Video lessons · 141109 Viewers
59 Video lessons · 59460 Viewers
52 Video lessons · 72771 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.