Personal Activities Calendar Program - Initialize And Pass Argument Variables With A Function

Personal Activities Calendar Program - Initialize And Pass Argument Variables With A Function
In the last part of the Personal Activities Calendar Program we built the PHP function that will send the Activity Entry web form to the browser. So far we used a PHP if statement to test if the web form has been submitted and if it hasn't, then the program will call the function which will send the form to the browser.

However, we need to add one more thing to this step in the program. Because the form has not been submitted yet, the input fields used in the form do not have any data assigned to them. So we do not have any data to pass with the function arguments (which are variables). So we need to initialize these variables to null before we send them. (If you need to refresh you memory about PHP functions, arguments and function calls, read my previous article.) We will put the code that initializes the variables to null just before the function call. In the table below, the input fields used in the web form are in the column on the left and the names we will give to our argument variables are in the right column.

Input Fields

act_title
act_desc
act_month_1
act_day_1
act_year_1
act_hour_1
act_month_2
act_day_2
act_year_2
act_hour_2
act_status
Function Arguments

$pass_act_title
$pass_act_desc
$pass_act_month_1
$pass_act_day_1
$pass_act_year_1
$pass_act_hour_1
$pass_act_month_2
$pass_act_day_2
$pass_act_year_2
$pass_act_hour_2
$pass_act_status

So far the if statement looks like this.

if(empty($_POST['submit']))
{
Activity_Entry_Form( );
}


Now we need to write the code to initialize the variables.

$pass_act_title = "";
$pass_act_desc = "";
$pass_act_month_1 = "";
$pass_act_day_1 = "";
$pass_act_year_1 = "";
$pass_act_hour_1 = "";
$pass_act_month_2 = "";
$pass_act_day_2 = "";
$pass_act_year_2 = "";
$pass_act_hour_2 = "";
$pass_act_status = "";


Next we need to add the arguments to the function call.

Activity_Entry_Form( $pass_act_title,
$pass_act_desc,
$pass_act_month_1,
$pass_act_day_1,
$pass_act_year_1,
$pass_act_hour_1,
$pass_act_month_2,
$pass_act_day_2,
$pass_act_year_2,
$pass_act_hour_2,
$pass_act_status );

Note--The arrow indicates that the code is wrapped to a second line and could really be all on one line.

Here are the finished changes to the ActivityEntry.php3 file.








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.