PHP Form Resetting
Posted: Thu Apr 13, 2006 10:26 am
I really have no idea why in the following script, all the fields in the form reset after I submit. I've looked at about 20 tutorials about this and they all say to do the same thing that I believe I'm doing...that is to make the value attribute of the various fields = to <?php echo $_POST['varname'] ?>. For some reason it doesn't work at all. To test it I've echoed one of the variables (the $client_email one) several times along the running of the script to see if it was being unset anywhere but it came back with the string it was set to every time, except in the form which is where I want it. Can anybody please help?
Code: Select all
<?php
function showForm(){ ?>
<form method="post" action="<?PHP echo $_SERVER['PHP_SELF']; ?>">
<div>
<font class="formtitle">Choose a type of avatar:</font>
<br>
<input type="radio" name="avatar_type" value="normal ">
Normal
<br>
<input type="radio" name="avatar_type" value="animated">
Animated
<br>
<br>
<font class="formtitle">Text desired on avatar:</font>
<input type="text" size="50" name="avatar_text" value="<?php echo $avatar_text ?>">
<br>
<br>
<font class="formtitle">Desired dimensions (not required):</font>
<input type="text" size="25" name="desired_dimensions" value="<?php echo $desired_dimensions; ?>">
</div>
Remember that a picture is worth a 1000 words and accordingly one should give a detailed description of what is desired in the following Description Area:
<br>
<textarea name="description_area" rows="10" cols="70"><?php echo $description_area; ?></textarea>
<br>
<br>
Your email:
<input type="text" size="40" name="client_email" value="<?php $client_email; ?>">
<br>
<br>
<input type="submit" name="submit" value="Send Request">
</div>
</form>
<?php }
?>
<?php
function showThankYou(){
echo 'Thank you for your request. An email asking you to confirm your request
should be sent to you shortly.';
}
?>
<?php
function checkEmail($email){
$qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
$dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
$atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
'\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
$quoted_pair = '\\x5c\\x00-\\x7f';
$domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
$quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
$domain_ref = $atom;
$sub_domain = "($domain_ref|$domain_literal)";
$word = "($atom|$quoted_string)";
$domain = "$sub_domain(\\x2e$sub_domain)*";
$local_part = "$word(\\x2e$word)*";
$addr_spec = "$local_part\\x40$domain";
return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
}
?>
<?php //declaring variables
$avatar_type=$_POST["avatar_type"];
$avatar_text=$_POST["avatar_text"];
$desired_dimensions=$_POST["desired_dimensions"];
$description_area=$_POST["description_area"];
$client_email=$_POST["client_email"];
$submit=$_POST["submit"];
$category='avatar';
$checker=false;
$subject="Request Confirmation";
$message="<h1>HTML E-mail</h1>
<p>This is an <b>HTML</b> e-mail.</p>";
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers.= "From: $from\r\n";
$from="FROM: <asukafan85@yahoo.com>";
?>
<?php
if(isset($submit)){
if(empty($avatar_type)){
echo 'Please select a type of avatar.'; ?>
showForm();<?php
unset($submit);
$checker=true;
}
//check email
if(checkEmail($client_email)==0){
echo 'Please enter a valid email address.';
$checker=true;
}
//shows thank you message if everything is ok
if(!$checker){
showThankYou();
mail($client_email,$subject,$message,$headers);
}
}
else{
//display form
showForm();
}
?>