jcstanley Posted October 18, 2007 Share Posted October 18, 2007 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 https://forums.phpfreaks.com/topic/73771-solved-error-handling-verification-return-values-back-to-form-on-error/ Share on other sites More sharing options...
hostfreak Posted October 18, 2007 Share Posted October 18, 2007 Store it in the session superglobal array: $_SESSION['description'] = $_POST['description']; Then inside your textarea tags on the "event_form.php" page, echo it: <textarea><?php echo $_SESSION['description']; ?></textarea> Then if you want, upon a successful submission, <a href="http://www.php.net/unset">unset()</a> it Link to comment https://forums.phpfreaks.com/topic/73771-solved-error-handling-verification-return-values-back-to-form-on-error/#findComment-372225 Share on other sites More sharing options...
Ingwar Posted October 18, 2007 Share Posted October 18, 2007 Hi jcstanley I suggest that you use xajax for checking are title and description filled. You can download it from http://www.xajaxproject.org, and it's very easy to use. I can write you that code for tomorrow if you want regards Link to comment https://forums.phpfreaks.com/topic/73771-solved-error-handling-verification-return-values-back-to-form-on-error/#findComment-372231 Share on other sites More sharing options...
jcstanley Posted October 18, 2007 Author Share Posted October 18, 2007 Thanks hostfreak that works perfectly Link to comment https://forums.phpfreaks.com/topic/73771-solved-error-handling-verification-return-values-back-to-form-on-error/#findComment-372642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.