You are here: Hard form validation issue « PHP Programming Language « IT news, forums, messages
Hard form validation issue

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация