Personal Activities Calendar Program - Integrating A Web Form Into A PHP Program

Personal Activities Calendar Program - Integrating A Web Form Into A PHP Program
In the last tutorial for the Personal Activities Calendar Program you built the HTML web form that you will use to collect the information about the activities you wish to add to your activities calendar program database. View Code for Sample Web Form

Now you are ready to begin coding the web application that will drive the calendar program. Most web applications are written as a group of small PHP programs that work together as a whole to run the application. This is an efficient method of writing a web application because it makes maintaining the individual sections of the application much easier.

We will begin coding the first of this group of PHP programs. This section will handle the collection of information for new activities and store that information in the database. In order to use the web form to collect this information, you will need the program to print the form to the webpage when it is needed. How will the program know when the web form is needed?

If you remember there are 11 pieces of information being collected by the web form variables.

act_title -- Title of activity

act_desc -- Description of activity

Time the activity will begin

Time the activity will end


If these variables are NOT empty, then the web form has already been filled out and submitted to the program. So of course, there is no need to print the form to the web browser again. But we really don't need to check all ten variables. Let's just check to see it the submit button on the web form has been used. We will use this line of code.

if(empty($_POST['submit'])) { print web form to browser }
else { process data }

What does this code say?

if(empty($_POST['submit'])) {print web form to browser}
If the submit variable is empty, the form has not been used yet. Therefore print the web form to the browser.

else { process data }
If the submit variable is not empty, then the web form has been filled out and submitted. In this case, process the incoming data.

We will name this program ActivityEntry.php3. And we will put this code just below the require_once statement for the config.php3 file. Here are the first few lines of this program. Take a look at the first few lines of the echo statement.

echo "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
. . .

As you can see in the echo statement, the code for the web form is placed between quotation marks. Because of this, we must escape any quotation marks that are part of the HTML code for the web form. Above, the two quotation marks in the doctype tag has been escaped with a \. You will do this for every quotation mark in the web form code.

This site needs an editor - click to learn more!

Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map

Content copyright © 2022 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.