Frosty
06-27-2002, 11:07 PM
I have the below simple PHP script for a form on my site that visitors fill out which submits the info to my email inbox. Does anyone maybe know how i can make it so that "all fields are required". Because right now alot of morons are leaving a bunch of fileds empty even though i clearly say "ALL fileds required" on my site. Isn`t there like a simple code or something i can add to it...or would i have to re-write the whole freakin script?
:confused:
<?
$youremail="bla@blabla.com";
$yoursubject="This is a message from bla";
$thankspage="http://www.blabla.com/thankyou.html";;;
mail("$youremail", "$yoursubject", "
First Name: $x_First_Name
Last Name: $x_Last_Name
Email Address: $x_Email
Confirm Email: $x_Email_Confirmed
Favorite Color: $x_Color
","From: $youremail\nReply-To:$youremail\nContent-Type: text/html;
charset=iso-8859-1: PHP/");
include "$thankspage";
?>
Elena
06-27-2002, 11:38 PM
Try something likeif (!$youremail) {
echo "<html><body><b><font color=red>You forgot something! Go back and try again!!!</font></b></body></html>";
}or for multiple fieldsif (!$youremail || !$yourname || !$yoursubject) {
echo "<html><body><b><font color=red>You forgot something! Go back and try again!!!</font></b></body></html>";
}This only works if the form is on one page and it calls a seperate file to process the information.. I think. I'm new to php also... soo :D
Frosty
06-28-2002, 12:58 AM
Thanks Elena,
Yeah i have a form on one page which calls the below script to send the info. I tried the below is that kind of correct...not really lol? I tried it and it`s sending the info to my email inbox like it`s supposed to but now even when i fill out every single field and hit "submit" i get a the message "You forgot something! Go back and try again!!!". That message is only supposed to show up if someone leaves a field blank...but now it shows up even when you fill out every single field...
<?
$youremail="bla@blabla.com";
$yoursubject="This is a message from bla";
$thankspage="http://www.blabla.com/thankyou.html";;;
if (!$First_Name || !$Last_Name || !$Email || !$Email_Confirmed || !$Color) {
echo "<html><body><b><font color=red>You forgot something! Go back and try again!!!</font></b></body></html>";
}
mail("$youremail", "$yoursubject", "
First Name: $x_First_Name
Last Name: $x_Last_Name
Email Address: $x_Email
Confirm Email: $x_Email_Confirmed
Favorite Color: $x_Color
","From: $youremail\nReply-To:$youremail\nContent-Type: text/html;
charset=iso-8859-1: PHP/");
include "$thankspage";
?>
Originally posted by Frosty
Because right now alot of morons are leaving a bunch of fileds empty even though i clearly say "ALL fileds required" on my site. :confused:
That was so funny :laugh: could'nt resist posting. LOL.
Actually while you do programming, you have to just think of morons on the net. Then you'll be all set :) Its like testing your pages in Netscape to see if you missed any table tag ;)
Frosty
06-28-2002, 01:04 AM
LOL...
Yeah but i have this plastered all over the page like 3 times:
ALL fields are required.
Please fill out all fields!
...and they still submit the freakin form have blank heh heh :D
mwatkins
06-28-2002, 01:07 AM
You have two ways of dealing with the "fields" issue - a scripted test within the browser - Javascript routine to check the contents of the fields in your form - do a google query on
javascript form processing
and you'll probably find what you need.
Or, as suggested already, process it at the back end and redraw the page with a warning if not all fields are filled out. One advantage of this might be in the case that you are validating some of the data entered against data you already have on the server - you can do the tests without sending all that data down to the browser.
Forcing people to fill out fields is half the battle -- you probably also want the data to be meaningful.
Can't tell you how many times I've filled out a form with a zip code of 90120 and a country code of Afghanistan.
Programmers can be morons too.
Elena
06-28-2002, 01:44 AM
This probably isn't it.. but in your form do you have<input type=text name=First_Name>and all the rest you listed that are required?
Shooot.. you also have to kill the script when it fails. Use this insteadif (!$First_Name || !$Last_Name || !$Email || !$Email_Confirmed || !$Color) {
echo "<html><body><b><font color=red>You forgot something! Go back and try again!!!</font></b></body></html>";
exit;
} Editted this one so many times I'm not even sure that will work.. LOL but its worth a try. :rolleyes:
Frosty
06-28-2002, 02:13 AM
Originally posted by Elena:
This probably isn't it.. but in your form do you have
Ah wait...that actually was it:
I have the below in my form. It wasn`t working before because i accidently left out the "x_" part earlier in the php script. Doh!
<INPUT TYPE=TEXT NAME="x_First_Name">
So i added it and it works perfect now. Thanks a bunch! :) :)