Hi, I have a form for customers to enter requests, this form posts to a php script which checks if all fields have been populated and, if so, sends the data to a database. If not all fields have been populated the user gets returned to the form and error messages appear to tell them what was missing.
My problem is that when the form is displayed with the error messages, all the data the user had entered is gone so they have to fill out the whole form again.
How do I make the form rebuild with the data entered?
here is my form:
And my php script:
There is more fields in the form but i have left these out here to shorten the code a bit, any help on sending the data back to the title and description fields would be very helpful,
thanks in advance.
My problem is that when the form is displayed with the error messages, all the data the user had entered is gone so they have to fill out the whole form again.
How do I make the form rebuild with the data entered?
here is my form:
Code:
<form id="ambercat" name="ambercatlog" method="post" action="ambercat.php">
<table>
<tr> <td><b>Subject Title</b></td>
<td><input size="17" name="query_title" type="text" class="textfield" id="query_title"></td></tr>
<tr><td><b>Description</b></td></tr>
<tr><td> <textarea cols="34" rows="6" name="Comments" id="description" onBlur="trim('Comments')" onfocus="doClear(this)"></textarea> </td>
</tr>
<tr><br/><td><input type="submit" name="Submit_query" value="Submit" /></td><br/><br/></tr>
<tr><td height="110"> </td> <td align="justify">
//error messages displayed here
<?php
if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
// echo '<ul class="err">';
foreach($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>',$msg,'</li>';
}
// echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?></td></tr>
</table>
</form>
Code:
<?
session_start();
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
$title = $_POST['query_title'];
$description = $_POST['Comments'];
//Input Validations
if($title == '') {
$errmsg_arr[] = 'Title missing';
$errflag = true;
}
if($description == '') {
$errmsg_arr[] = 'Description missing';
$errflag = true;
}
//If there are input validations, redirect back to the form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: ambercat_log.php");
exit();
}
//send to database
include('connect.php');
@mssql_query("INSERT INTO Customer_Calls (Title, Description)
VALUES ('$title', '$description')");
mssql_close();
$result5 = @mssql_query;
//Check whether the query was successful or not
if($result5) {
header("location: ambercat_submit.php");
}
?>
thanks in advance.
Comment