I'm an absolute beginner with PHP and searched the web for a contact form. I followed the steps and the form works fine, emailing me when someone fills it in and then going to a success page once it's sent. I set this up yesterday.
Today however I have received a blank mail, as though the form has sent without being filled in.
Below is the PHP and HTML I'm using. Any advice on how to stop it sending blank emails would be really appreciated. I really don't know what I'd need to do to stop this.
I don't see anything for form validation (ie, making sure a field is filled out, making sure it's only letters for name, etc.) So anyone could bring up the form and hit SUBMIT without filling anything out. This _could_ explain what happened, but it's just a guess.
I never thought of that, as I say, I'm new to PHP.
I've searched for a tutorial on doing this. Do you think the method here would be suitable.
Sorry for asking what is probably a naive question but I don't know php so don't know how to tell between good processes and bad processes.
Many thanks.
Everybody has to start somewhere, right? :) We all did.
There is client-side validation (JavaScript), and there is server-side validation (PHP, or whatever dynamic language you're using.) There are good and bad things about both; it's up to you.
Client-side validation GOOD: it saves bandwidth and server CPU.
Client-side validation BAD: JavaScript can be disabled in the browser, bypassing form validation.
Server-side validation GOOD: it can't be bypassed.
Server-side validation BAD: you have to actually submit the form in order to validate the entries, which takes up network bandwidth and server CPU time/resources.
These are over-simplified, of course, but you get the basic principle.
If you have the time (and patience), do both. The JavaScript (client-side) validation will be used in 96% of submissions, and the client-side can be a redundant back-up validator for those who choose to disable JavaScript (or if JavaScript is not an option.)
Another thing, for those of the mind: Set it so that the form submits via JavaScript - that way, if JavaScript is disabled, a majority of the forms cannot be submit. There are ways around this, of course, but it's a thought.
Bookmarks