Hard form validation issue

This is a discussion on Hard form validation issue within the PHP Language forums, part of the PHP Programming Forums category; I have a mail form, where I would like the users to enter a secret code and check one checkbox ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-23-2006
John
 
Posts: n/a
Default Hard form validation issue

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...";
}
}

?>


Reply With Quote
  #2 (permalink)  
Old 05-23-2006
Sjoerd
 
Posts: n/a
Default Re: Hard form validation issue

John wrote:
> What's wrong with my
> nice newbie-code? Here it is:


This is wrong:
> if(strcmp($_POST['check'],"") !="yes"))


These are correct:
if (0 == strcmp($_POST['check'], "yes"))
if ($_POST['check'] == "yes")
if (empty($_POST['check'])

Reply With Quote
  #3 (permalink)  
Old 05-23-2006
John
 
Posts: n/a
Default Re: Hard form validation issue

> John wrote:
> > What's wrong with my
> > nice newbie-code? Here it is:

>
> Sjoerd <sjoerder@gmail.com> wrote:
> >This is wrong:
> > if(strcmp($_POST['check'],"") !="yes"))

>
> These are correct:
> if (0 == strcmp($_POST['check'], "yes"))
> if ($_POST['check'] == "yes")
> if (empty($_POST['check'])
>




I tried to rewrite the process.php and also add another checkbox to be
cheked, but still something is wrong. Here is the code, can you see the
error in the code?


<?php


//check if secret code is not filled in and if checkbox are not cheked
if (empty($_POST['secret_code']) && (empty($_POST['check']))
//is so then exit
{
exit();
}
//check if secret code are submitted and if it matches
if (strcmp($_POST['secret_code'],"SECRET"))

//check if checkbox are cheked "yes"
//and if checkbox 2 are cheked "yes"
if (0 == strcmp($_POST['check'], "yes"))
if (0 == strcmp($_POST['check2'], "yes"))


if ($_POST['check'] == "yes") && ($_POST['check2'] == "yes")


//then start the mailing process

{


$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, sucess!</p>");
}

}
else
{
echo "You failed to enter secret code, submit cancelled...";
}
}

?>


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:25 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0