Personal Activities Calendar Program - Printing The Web Form With A Function

Personal Activities Calendar Program - Printing The Web Form With A Function
In this tutorial, we will continue to work on the ActivityEntry.php3 program file for the Personal Activities Calendar Program project. So far we have written the code for the part of the program that tests if the Activity Entry web form has been filled out and submitted to the program.

if(empty($_POST['submit'])) { echo form to webpage }
else { process data }

If the $_POST['submit'] is empty, the submit button on the web form has not been used and the form has not been filled out. In this case, the program will send the web form to the browser via an echo statement. Here is the code so far. This works fine if this was the only time that the program needed to send the web form to the browser. But we need to consider that this same web form will be sent to the browser in three instances.

  1. As we have coded our program so far, the form will be sent when the form has not been filled out ($_POST['submit'] is empty) and we want to add a new activity to the calendar.
  2. Once the form is filled out, the $_POST['submit'] variable will not be empty. The program will then check for mistakes in the submitted data. If there is missing information because you did not fill out the form completely, an error message is sent to the browser along with the web form again.
  3. You might need to change the information about an activity that you have previously entered into the database. For example, you might want to change the status from incomplete to complete. When you need to edit a previously entered activity, the form will be sent to the browser for the changes.
As of now, the echo statement is still coded within the if statement in the ActivityEntry.php3 file.

if(empty($_POST['submit'])) { echo form to webpage }

But we will need to use this same echo statement for all three instances. So we can make our program more efficient if we change the echo statement to a function. Then any time the program needs the web form, we will call the function. Therefore, we will need to change the echo statement in the code above to a function call.

if(empty($_POST['submit'])) { function call }

Next →








This site needs an editor - click to learn more!



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





Content copyright © 2023 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.