Jump to content

[SOLVED] Error Handling & Verification: Return values back to form on error


jcstanley

Recommended Posts

Hi

 

I have a form 'event_form.php' with 2 fileds: Title and Description.

 

On submit the 'save.php' script is called which performs the following:

 

$title=$_POST['title'];
$description=$_POST['description'];


if (trim($title)=='' || strlen(trim($title)) < 1)
{ 
	echo '<body bgcolor="#FFFFFF">';
	echo '<p align="center" style="margin-top: 0; margin-bottom: 0">';
	echo '<b><font face="Tahoma" size="4" color="#FF0000">Incomplete Form</font></b></p>';
	echo '<center><p><b><font face="Tahoma" size="2" color="#FF0000">Please enter a Title</font></b></p>';
	echo '<center><p><font face="Tahoma" size="2" color="#000000"><a href=events_form.php>Try Again</a></font></P>';
	exit;
}

if (trim($description)=='' || strlen(trim($description)) < 1)
{ 
	echo '<body bgcolor="#FFFFFF">';
	echo '<p align="center" style="margin-top: 0; margin-bottom: 0">';
	echo '<b><font face="Tahoma" size="4" color="#FF0000">Incomplete Form</font></b></p>';
	echo '<center><p><b><font face="Tahoma" size="2" color="#FF0000">Please enter a Description</font></b></p>';
	echo '<center><p><font face="Tahoma" size="2" color="#000000"><a href=events_form.php>Try Again</a></font></P>';
	exit;
}

 

The problem is that if the user fills out the description field (which could be quite lengthy) but forgets to enter a title the error message will be displayed.  Once the 'Try Again' link is clicked the user is taken back to the form but will have to enter the description again.  Is there any way the decription value (and title value) can be passed back to the form?

 

Many thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.