SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict XiledWeb's Avatar
    Join Date
    May 2005
    Location
    Nashville
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Contact Form Help

    Hi, I've been asked to develop a basic contact form for a non profit organization and I'm having a spot of trouble with the processing of the form.

    The code looks good (to me), but I'm sure a regular at this kind of thing can pinpoint my error(s).

    The code is as follows:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Lamplighters Contact Form</title>
    <link href="form.css" rel="stylesheet" type="text/css" media="all" />
    </head>
    <body>

    <?php

    if(isset($_POST['sendMail']))
    {

    $to "email@address.com";
    $name trim($_POST['name']);
    $email trim($_POST['email']);
    $phone trim($_POST['phone']);
    $show trim($_POST['show']);


    if(((empty(
    $name))||(empty($email))||(empty($phone))||(empty($show))))
    {

    echo 
    'Sorry, you forgot to fill out some required fields. ';
    echo 
    '<a href="javascript:history.back(1)">Try again</a>';

    } else {

    if(!
    strstr($email "@"))
    {

    echo 
    'Please enter a valid email address. ';
    echo 
    '<a href="javascript:history.back(1)">Try again</a>';

    } else {

    $send mail($to "Contact message from YourWebsite" "This email was sent from your website.\n\n".$name." send this message from ".$email.":\n\n".$phone."\n\nClick reply and it will send to this email." "From: Contact Form Reply-to: ".$email);

    if(
    $send)
    {

    echo 
    'Mail sent successfully.';

    } else {

    echo 
    'There was an error sending the mail!';

    }
    }
    }

    } else {

    echo 
    '

    <form name="contact" method="post" action="'
    .$_SERVER["PHP_SELF"].'">
    <p>Contact us form:</p>
    <p><label for="name">Name:</label>
       <input type="text" id="name" size="35" /></p>
    <p><label for="email">Email Address:</label>
       <input type="text" id="email" size="30" /></p>
    <p><label for="phone">Phone Number:</label>
       <input type="text" id="phone" size="20" /></p>
    <p><label for="show">Which Show:</label>
       <select id="Required Show" name="show">
       <option>Show 1</option>
       <option>Show 2</option>
       <option>Show 3</option>
       <option>Show 4</option>
      </select></p>
    <p><input type="submit" /></p>
    </form>
    </body>
    </html>

    '
    ;

    }
    ?>

  2. #2
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing
    PHP Code:
    if(isset($_POST['sendMail'])) 
    to
    PHP Code:
    if(isset($_POST['submit'])) 
    and change
    PHP Code:
    <p><input type="submit" /></p
    to
    PHP Code:
    <p><input name="submit" type="submit" /></p
    Tina

  3. #3
    SitePoint Addict XiledWeb's Avatar
    Join Date
    May 2005
    Location
    Nashville
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Tina, that seems to have fixed that problem.

    Now though, I'm getting the error message "Sorry, you forgot to fill out some required fields. Try again" even though all my fields are filled in correctly.

  4. #4
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if this is the answer (i'm new to php) but you have an additional set of parenthesis on this line
    PHP Code:
    if(((empty($name))||(empty($email))||(empty($phone))||(empty($show)))) 
    change it to
    PHP Code:
    if((empty($name))||(empty($email))||(empty($phone))||(empty($show))) 

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Looks like Tina88 has a point, turn up your error reporting on any page temporarily and get more clues as to what is wrong:

    PHP Code:
    ini_set('display_errors' 1) ;
    error_reporting(E_ALL); 


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
  •