g
Printer Friendly Version

editor  
BellaOnline's PHP Editor
 

Personal Activities Calendar Program - Error Message For Missing Form Data - 2

Now that we have completed the changes to the function call in the Activity Entry script, we need to add the changes to the Activity_Entry_Form function that will handle the error message. We need to add the new parameter variable to the list of variables being received by the function. If we don't, then the function will not recognize the $error_message even if we send it. So let's add the receiving variable called $prev_error_message to the list.

//print function with passed arguments
function Activity_Entry_Form ( $prev_error_message, $prev_act_title, $prev_act_desc, $prev_act_month_1, $prev_act_day_1, $prev_act_year_1, $prev_act_hour_1, $prev_act_month_2, $prev_act_day_2, $prev_act_year_2, $prev_act_hour_2, $prev_act_status )

Note--The code above is wrapped. It could really be all on one line.

When the value of the $prev_error_message is set to yes, we will want to display an error message on the form. We can do this with a simple if statement and a new variable we will call $message_text. This variable will hold the text of the error message. We will first initialize this variable to null. Then if the $prev_error_messaage is equal to yes, we will set the variable to the text of the error message.

$message_text = "";
if ( $prev_error_message =="yes" )
{ $message_text = "Sorry, please fill in all required fields <br><br>"; }
Note--The code above is wrapped. It could really be all on one line.

1. We have set the initial value of the $message_text to null. If the program has not encounter any missing data, the $message_text remains set to null and no message will appear in the form.

2. If the program has encounter missing data, we will set the $message_text variable to the error message we wish to show on the web form.

Finally, we will add the $message_text variable to the web form code in the location where we wish the error message to display. If it is not set to null, the message will be displayed.

...
<h1>Add An Activity</h1>
<form action=\"ActivityEntryStep4.php3\" ...>
$message_text

← Back







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