PHP contact form
- Started
- Last post
- 13 Responses
- juhls
As it stands now, I have almost finished the form.
What I discovered is that it sends the email even if the form is not valid. I tried various ways to change it, but I think I'm over-thinking things. I even tried putting all of the validation parts in functions. Any suggestions?
Thanks for the help!
- juhls0
To clarify: it sends if there is an email address in the "Email" field.
- neverblink0
if($valid==true){
$ret = , $subject, $message, $headers);
}
- juhls0
It works fine. Now it just says that "ret" is undefined. Only if the form does not submit. So I will play around with it.
- section_0140
If the email is invalid, the $ret variable in the if statement that states whether or not the email was sent won't be defined, therefore it's invalid. You need to nest that if statement in the validation if statement.
If that makes sense.
- rounce0
if(isset($ret) && $ret) { ... }
- moth0
I hate that about PHP.
Having to declare everything before you use it.
- sounds like marriage!ideaist
- http://www.sadtrombo…ideaist
- I like PHP more than I like jQuery for some reason. More simple for my mind ;)juhls
- adev0
Your only guard against spambots is the post button?
A little trick I've recently started doing is added a input text field into the form, then hiding with javascript when the dom is ready. In PHP I then do a check to see if a bot fills any text into this field (usually it's name is "fax" or something generic a bot might think is a real field). It really cut down on the fake emails coming through.
Works until the spam bots start parsing the JS code....
- pylon0
adev, couldn't you do something similar by wrapping it in a div that's visibility is hidden, via css? Or do the spambots parse that as well?
I've also heard of people dropping the entire form in a randomly named page that is included via iframe.... sounds a little weird though. Surely bots see iframes?
- http://robmalon.com/…juhls
- Sounds interesting as well.juhls
- damn it. I thought I had an original idea! loladev
- RW0
- adev0
pylon, I figured if google doesn't look at javascript for SEO (AFAIK), I doubt a spambot would. So using Javascript to hide the field seemed better than just CSS which google (and presumably a smart spambot) can catch.