473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 = "se*********@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...";
}
}

?>
May 23 '06 #1
2 1372
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'])

May 23 '06 #2
> John wrote:
What's wrong with my
nice newbie-code? Here it is:


Sjoerd <sj******@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 = "se*********@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...";
}
}

?>
May 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
0
by: Jakob Kirkegaard | last post by:
I've been playing around with Phrame the last couple of days in the search for a development framework for future projects. I stumbled upon one issue which I can't figure out how to handle most...
11
by: Jim | last post by:
Hi, I keep getting form results emailed to me that would indicate a form from my web site is getting submitted with all fields blank or empty, but my code should preventing users from proceeding...
5
by: Danny | last post by:
Does anybody have a nice method of forcing a user to enter a value into a form using asp? I think the best is to have a popup when they hit submit that will stay on the same page and then just...
3
by: Shabam | last post by:
I know that dotnet allows for form field validation. However I'm looking to customize the error message display and am wondering if it's possible to do what I need. Example: Suppose in a...
5
by: jinukosh | last post by:
We are having multiple submit buttons with form validation on a single form. By default a button is selected and the elememts included in the form is validated. If we try to add 2 forms to an...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
18
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.