Hey,
Ok I have the following at the top of my form page:
<?
session_start();
//user messages
$required_missing_msg = 'Required Fields Missing';
$success_msg = 'Success';
$fail_msg = 'Error';
//email information
$email_user = 'email';
$email_domain = 'domain.com';
$email_from_user = 'enquiry';
$email_from_domain = $_SERVER['SERVER_NAME'];
$mail_subject = "SkIN Online Form";
//init code
$show = "init";
//get self filname
$fullpath = split('/',$PHP_SELF); $c = count($fullpath); $c--; $self = $fullpath[$c];
if ($_POST)
{
//get list/put form variables into array post_name => post_value
$required = explode(",", $_POST['required']);
$data = array();
foreach($_POST as $key => $value)
{
if(($key!='required')&&($key!='Submit')&&($key!='PHPSESSID')&&($key!='sid'))
{
$data["$key"] = $value;
if (empty($value)) //check for required
{
foreach($required as $req)
{
if($key==$req)
{
//$data["$key"] = '!*Required*!';
$msg = $required_missing_msg;
$show = "form";
}
}
} else // add to message
{
$message .= $key.": \n".$value."\n \n";
}
}
}
if ($show == "init")
{
//put data into mail and send
$toaddress = $email_user.'@'.$email_domain;
$fromaddress = "From: ".$email."\n";
$email = mail($toaddress, $mail_subject, $message, $fromaddress);
//check for sending error
if ($email)
{
$msg = $success_msg;
$show = "Msg";
} else
{
$msg = $fail_msg;
$show = "Msg";
}
}
}
function selector($label, $data, $input_data)
{
if ($data==$input_data)
{
echo ' checked';
}
}
?>
I have this at the top of my form:
<? echo $msg; ?>
<? if ( ($show == "form") || ($show == "init") ){ echo ?>
<form name="feedback" method="post" action="<? echo $self.'?'.strip_tags(SID);?>">
and this at the bottom of my form:
<? ;} ?>
</form>
I have a hidden field that lists all of the fields that are required. Now, when a user submits this and they miss out something that is required, it loads the form again, but does not fill in what they had already filled in. So if I had a really long form and they answered 9 out of 10 required fields, it will tell them to try again but it deletes everything in the other 9 fields. Any ideas how I get it to show the results? I've tried:
value="<? echo $variable;?>"
No luck.
Cheers,
Chris