Small contact form needed for website

Commissario
Joined
23 Nov 2004
Posts
42,925
Location
Herts
I've currently put in a rather basic, and pretty terrible, PHP contact form onto my site.

http://jmcadam.com/contact.htm

I'd like something more simple and compact, and when there's an error (as in incorrect email format/empty field) an error appears next to the box, not taken to a nasty white page with black text.

The same is when a message is sent, greeted with a white page with details and a link to the homepage.

Not really sure which language is best for this, any links or input as usual cheers guys :)
 
Last edited:
OK I've given that a go, but I'm not quite sure how to set it up so that it sends to me? :confused:


In your form tag, you give it the url to your php file which will process your form data.

Code:
<form id="contactForm" method="post" action="formProcess.php">

It's in your php file that you'll run server side validation and do stuff with the data returned. There are a bunch of scripts available if you google "php form script".
 
Right I need to set it now so that all fields are required because I keep getting people submitting blank forms to test it! Would this be done in the PHP coding?
 
Right I need to set it now so that all fields are required because I keep getting people submitting blank forms to test it! Would this be done in the PHP coding?

Both, you want it done on PHP and the above mentioned before.
If you do it at the client end, it's faster because no information is exchanged until the rules are fulfilled.
You do it at the server end as well because nasty kids (and hairy men) will send you junk data to try and wreck your database.
 
Both, you want it done on PHP and the above mentioned before.
If you do it at the client end, it's faster because no information is exchanged until the rules are fulfilled.
You do it at the server end as well because nasty kids (and hairy men) will send you junk data to try and wreck your database.

This is a contact form, so nothing is going in the DB.. at least I doubt it is. Still a good idea to validate and secure any input though with PHP.
 
Well it works, it's not very pretty though.

I was able to send only whitespace, you might want to check for this in PHP, or set a minimum character length.
 
True, it needs a fair bit of work. Will address these issues once I've worked out how - I'm very new to PHP!
 
When specifying labels, use the "for" attribute with the ID of the element it is.. er.. for.

E.g.:
Code:
<label for="name">Name:<span class="small">Enter your name</span></label>
<input type="text" name="name" id="name">
You'll also need to meddle with the widths of things, as that's why they are pushing the text boxes onto the next line.

Also, try not to use "float" for things like forms. "float" is a bit of a special CSS property that should, ideally, only be used as a last resort. :)
 
Seriously guys surely you should be pointing him in the direction of something like http://wufoo.com/ no?

Been doing software and website development for 15 years and I'll still add a Wufoo form where it makes sense. This is one of those times.

I appreciated you might just be wanting to learn something though Maccy.
 
Back
Top Bottom