How can I php validate this simple php form?

Hi there, I am wondering how to insert validation into this code:

[php]<?php
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘On’);

// Featured first in thec ontact html page (contact.html) is name, so we define it as a variable to be pulled
$name = “name”;

// Next comes email address of the person sending the message
$sender_email= “sender_email”;

// the phone number of the person sending the message
$phone = “phone”;

//the subject of the message
$subject =“subject”;

// The message
$message=“message”;

//Building a message that is sent, out of several variables:
$mailcontent = 'Name: '.$name."\n"
."\n"
.'Email Address: '.$sender_email."\n"
."\n"
.'Message: '.$message."\n";

// From
$header=“from: $name $subject <$sender_email>”;

// Enter your email address
$to =‘[email protected]’;
$send_contact=mail($to,$subject,$mailcontent,$header);

// Check, if message sent to your email
// display message “We’ve recived your information”
if($send_contact){

header( ‘Location: contactthankyou.php’ ) ;

}
else {
echo “ERROR”;
}
?>[/php]

And then,

For the Javascript, someone helped me out and created this, but there seems to be an error on line 5!
(where it says this: var form = document.getElementById(“contactform”); )

[code][/code]

Any help, especially with adding in php validation would be very helpful!

Thx!

What type of validation?

There is nothing wrong with the javascript on that line. What is the error? Did you add id=“contactform” to your form?

Hello,

I am trying to validate these items (see the form below) with both Javascript, and php.

Yep, the form has an id=“contactform”

[code]

Contact Vanadia

        Your Name: <br /> &nbsp; <input type="text" name="name">  <br />

        <br/>Email Address: <br /> &nbsp; <input type="text" id="sender_email"> <br /> 

        <br/>Phone Number: <br /> &nbsp; <input type="text" name="phone"> <br />
        
    	<br/>Message Subject: <br /> &nbsp; <input type="text" name="subject">  <br />
    </p>
</div>

<div id="transboxrightcontactform">
    <p> 
        Message:<br />
        <textarea name="message" rows="20" cols="32"></textarea>
    </p>
    <input type="submit" value="Submit" 
       style="display: block; margin-left: auto; margin-right: auto;"> <br>
</div>
[/code]
Sponsor our Newsletter | Privacy Policy | Terms of Service