Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP Contact Form Validation - HELP!

Guest
May 06, 2010 May 06, 2010

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!

TOPICS
Server side applications
653
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 06, 2010 May 06, 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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 10, 2010 May 10, 2010

Hi, thanks for the reply, but I was hoping to keep the same effect I currently have with the validation I have in place.

But im not sure if my current validation is working fine or not, as I keep receiving blank emails from (unkown) but with the MDS2010 Enquiry title. But if I try to send an empty contact form from my site it wont let me as the validation seems to work as it asks for email, name etc.

If i fill it out correctly, I recieve an email which is perfectly fine. So what I dont understand is how am i getting the blank emails??

I'd really like to know whats going on because at the moment im not sure whether some ones requesting something or whether its something else???

Any ideas, please...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 10, 2010 May 10, 2010
LATEST

sorry posted twice

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines