|
Posted by John on 10/10/77 11:48
I have a mail form, where I would like the users to enter a secret code and
check one checkbox before the form are processed and the values can mailed.
Otherwise stop and display an error. But it won't work. What's wrong with my
nice newbie-code? Here it is:
The form:
<div>
<form method="post" action="process.php">
<p>Name:</p>
<input name="name" type="text" />
<p>Email:</p>
<input name="email" type="text" />
<p>Subject:</p>
<input name="subject" type="text" />
<p>Message:</p>
<textarea name="message" rows="6"></textarea>
<p>Enter secret send-code:</p>
<input name="secret_code" type="text" />
<p>Agree to terms?:</p>
Yes <input name="check[]" type="checkbox" value="yes" />
No <input name="check[]" type="checkbox" value="no" />
<br />
<input type="submit" name="submit" value="Send" /><input type="hidden"
name="do" value="send" /><input type="reset" name="reset" value="Reset" />
</form>
</div>
Here is process.php:
<?php
//validating input fields and checkbox, secret code is SECRET and required
checkbox value has to be "yes"
if (empty($_POST['secret_code']))
{
exit();
}
if (strcmp($_POST['secret_code'],"SECRET"))
if(strcmp($_POST['check'],"") !="yes"))
{
exit();
}
if(strcmp($_POST['check'],"yes"))
{
$do = ($_POST['do']);
if($do == "send")
{
$recipient = "secret_mail@somedomain.com";
$subject = ($_POST['subject']);
$name = ($_POST['name']);
$email = ($_POST['email']);
$message = ($_POST['message']);
$formsend = mail("$recipient", "$subject", "$message", "From: $email
($name)\r\nReply-to:$email");
echo ("<p>Thanks, success!</p>");
}
}
else
{
echo "You failed to enter secret code, or you didn't agree to the terms,
submit cancelled...";
}
}
?>
Navigation:
[Reply to this message]
|