g
Printer Friendly Version

editor  
BellaOnline's PHP Editor
 

Personal Activities Calendar Program - Error Message For Missing Form Data

In the last tutorial, we wrote the part of the Activity Entry script that will handle the possibility that the web form has been submitted but the user has not supplied all the required data. First, we set the values for the variables that we will pass to the Activity_Entry_Form function. The value for each variable is set to null if the input data is missing and, if not, it is set to the value of the $POST[''] data. Finally, we set the $error_message variable to yes if there is missing data from any of the required form fields. This will tell the program to display an error message when it displays the web form again. Now, let's work on handling the error message.

There are two changes we need to make to the Activity Entry script. Because we will be passing this new $error_message variable with the function call, we need to add this variable to the list of parameter variables that are sent to the function.

//If $error_message has been changed to yes, call function to print form again

if ($error_message == "yes")
{
Activity_Entry_Form( $error_message, $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 code above is wrapped. It could really be all on one line.

Also, because we will be coding the Activity_Entry_Form function to expect this new variable every time it is called, it will be expecting it even when the form is displayed for the first time. Therefore, we need to add the variable to the function call in the first part of the script. But we can't send this variable without initiating it first. So let's add that to the code too.

//If the $_POST submit is empty, call function to display form for the first time

if(empty($_POST['submit']))
{ $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 = "";

//Set the $error_message to null
$error_message = "";


Activity_Entry_Form( $error_message, $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 code above is wrapped. It could really be all on one line.

Next →







This site needs an editor - click to learn more!

PHP Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 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 Editor Wanted for details.



| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2013 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor