How can I php validate this simple php form?

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

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

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

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

// Enter your email address
$to =‘[email protected]’;

// Check, if message sent to your email
// display message “We’ve recived your information”

header( ‘Location: contactthankyou.php’ ) ;

else {
echo “ERROR”;

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”); )


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


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?


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

Yep, the form has an id=“contactform”


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 />

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