PDA

View Full Version : Contact From Validation Help



lcot
10-03-2010, 07:40 PM
Hello, I have a contact form here... http://livingfortodayband.co.uk/basement2/contact.php

This is just a simple form with no validation or spam protection. It just works. I have chosen to start simple and work up as I am no expert in php, I don't know a lot to be fair...

My next step is validation of the form fields but honestly I don't know where to start. I have followed a few tutorials and they have not worked so I was wondering if there is someone who would be willing to assist me in working this code out.

The style I am going for is like this... http://junglejap.com/FormTest/

I have found this page but I am not sure how to implement the code into my page... http://bassistance.de/jquery-plugins/jquery-plugin-validation/

here is the form on the php page I am working in html:

<form method="post" action="contact.php" id="contactform">
<ol>
<li>
<label for="name">First Name <span class="required">*</span></label>
<input id="name" name="name" class="text">
</li>
<li>
<label for="email">Your email <span class="required">*</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="artist">Band/Artist Name</label>
<input id="artist" name="artist" class="text">
</li>
<li>
<label for="subject">Subject<span class="required">*</span></label>
<input id="subject" name="subject" class="text">
</li>
<li>
<label for="message">Message <span class="required">*</span></label>
<textarea id="message" name="message" class="text" rows="6" cols="50"></textarea>
</li>
<li class="buttons">
<input name="imageField" id="imageField" src="images/send.jpg" class="send" type="image">
<div class="clr"></div>
</li>
</ol>
</form>

I will be so grateful if someone can help me out in this...
Thanks!

fastsol1
10-03-2010, 08:23 PM
The method they are using in this example is javascript - http://junglejap.com/FormTest/ which for a simple contact form would probably be ok cause you aren't submitting anything to a database that truly needs to be validated for sql injection and other malicious things. The jquery example is cooler but still a version of javascript cause the fields are still only validated on client side and not fully on server side once it's finally submitted.

I reality the best and friendliest way is to use javascript to try to enforce the form being filled out right, but if the person turns off javascript in their browser it won't tell them anything which is why you always need to validate on server side using php once the form has been fully submitted

lcot
10-03-2010, 08:27 PM
ok ... :) where do I start? I really don't even know where to look :/

lcot
10-05-2010, 05:28 PM
Hello, I have a contact form here... http://livingfortodayband.co.uk/basement2/contact.php

This is just a simple form with no validation or spam protection. It just works. I have chosen to start simple and work up as I am no expert in php, I don't know a lot to be fair...

My next step is validation of the form fields but honestly I don't know where to start. I have followed a few tutorials and they have not worked so I was wondering if there is someone who would be willing to assist me in working this code out.

The style I am going for is like this... http://junglejap.com/FormTest/

I have found this page but I am not sure how to implement the code into my page... http://bassistance.de/jquery-plugins...in-validation/

I have been told the styles above are done or can be done via javascript so i thought i'd request some specialist help as I have no idea in this field unfortunately.

This is the php code above everything in the contact.php page:


<?php

/* Subject and Email Variables */

$emailSubject = 'Basement Studio Web Enquiry';
$webMaster = 'lukecottingham@hotmail.co.uk';

/* Gathering Data Variables */

$name = $_POST['name'];
$email = $_POST['email'];
$artist = $_POST['artist'];
$subject = $_POST['subject'];
$message = $_POST['message'];

$body = <<<EOD
<br><hr><br>
Name: $name<br>
Email: $email<br>
Artist: $artist<br>
Subject: $subject<br>
Message: $message<br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$seccess = mail($webMaster, $emailSubject, $body, $headers);



?>

Below is the form on the website:

<form method="post" action="contact.php" id="contactform">
<ol>
<li>
<label for="name">First Name <span class="required">*</span></label>
<input id="name" name="name" class="text">
</li>
<li>
<label for="email">Your email <span class="required">*</span></label>
<input id="email" name="email" class="text" />
</li>
<li>
<label for="artist">Band/Artist Name</label>
<input id="artist" name="artist" class="text">
</li>
<li>
<label for="subject">Subject<span class="required">*</span></label>
<input id="subject" name="subject" class="text">
</li>
<li>
<label for="message">Message <span class="required">*</span></label>
<textarea id="message" name="message" class="text" rows="6" cols="50"></textarea>
</li>
<li class="buttons">
<input name="imageField" id="imageField" src="images/send.jpg" class="send" type="image">
<div class="clr"></div>
</li>
</ol>
</form>

I will be so grateful if someone can help me out in this...
Thanks!

Beverleyh
11-04-2010, 02:30 PM
I've used this in the past and found it quite easy to use: http://livevalidation.com/