SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Zapppa's Avatar
    Join Date
    Aug 2009
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help on a contact form please!

    Hi, I am having some difficulty sorting verification on my form.

    I just want to include something that will not proccess the form unless all the fields are filled in.

    At the minute it will still send even if the name etc is left out.

    Any help greatly appreciated.



    Code PHP:
    <?php
    if (isset($_POST['submit'])) {
      switch($_POST['contact_type']) {
          case 'Customer Services':
          $to = 'm1@gmail.com';
          break;	
    	case 'K Ltd':
          $to = 'm1@gmail.com';
          break;  
        case 'K America':
          $to = 'm1@gmail.com';
          break;
    	   case 'K Germany':
          $to = 'm1@gmail.com';
          break;
      }
     
      $subject = "K SITE ENQUIRY";
      $name_field = $_POST['name'];
      $email_field = $_POST['email'];
      $message = $_POST['message'];
     
      if (strlen(trim($message)) > 0) {
     
        $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
     
        if (mail($to, $subject, $body)) {
          echo "<h3>Thanks! Your email has been sent <br />We will answer your enquiry as soon as possible.</h3>";
        } else {
          echo 'Cannot sent mail';
        }
      } else {
        echo "<h3>Error! <br />Please ensure that all fields are filled out in order to email us!</h3>";
      } 
    } else {
      echo "blarg!";
    }
    ?>


    Code HTML4Strict:
    <form method="POST" action="mailer.php">
                  Your Name:<br />
       <input type="text" name="name" size="24" /><br />
       <br />
     
       FAO:<br />
     
        <select name="contact_type">
        <option>Customer Services</option>
        <option>K Ltd</option>
        <option>K America</option>
        <option>K Germany</option>
    	</select>
     
       <br /><br />
     
       Your Email:<br />
       <input type="text" name="email" size="24" /><br />
       <br />
       Your Message:<br />
       <textarea rows="10" name="message" cols="55" /></textarea>
       <br />
     
       <p>Please ensure that you have filled out all important information before submitting.</p>
       <input type="submit" value="Submit" name="submit" />
    </form>



  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,492
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Right now you only test if the message contains anything. Add other if's that check the other fields' content. And only send the message if everything is ok.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This PHP form validation script may be of help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •