Skip to main content
May 6, 2010
Question

PHP Contact Form Validation - HELP!

  • May 6, 2010
  • 1 reply
  • 713 views

Hello,

I've created my contact page on my website but I'm not happy with the validation and im getting emails through which are empty and with no contact details??

Could someone please help me!

This is my php code which is linked to my html page

<?php
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
    mail( "contactus@mammothdesignstudios.com", "MDS2010 Enquiry",
    $message, "From: $email" );
  header( "Location: http://www.mammothdesignstudios.com/thanks.html" );
?>

I have just used spry for validation but realise this is not the best way to go.

Could someone view my code www.mammothdesignstudios.com/contact_us.html

I'd really appreciate someones help on this,

Thank you!

This topic has been closed for replies.

1 reply

May 6, 2010

You can create a simple validation as below:

$error = array();

if (empty($_REQUEST['email'])) {

     $error[] = "The email is empty";

}

.... add any other validations u want.

Then add this

//check no errors

if(!$error) {

     mail( "contactus@mammothdesignstudios.com", "MDS2010 Enquiry", $message, "From: $email" );

}

Thus will prevent email to be send if there's any error occurs.

On html page u can add this if u want.

<p>

     <?php if ($error) {
            echo '<ul>';
                foreach ($error as $alert) {
                echo "<li>$alert</li>\n";
                }
            echo '</ul>';
      } ?>

</p>

May 10, 2010

sorry posted twice