Contact Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason

    Contact Form

    I'm struggling with this email code and I'm not php freak since I'm
    starting to learn php stuff. Could use some help...

    It seems that I get too many parse errors all over and cannot figure
    went wrong since most of these appears right to me...

    <?PHP

    $to = "scoobyood@jace 41.com" ;
    $name = $_POST['name'] ;
    $email = $_POST['email'] ;
    $subject = $_POST['subject'] ;
    $message = $_POST['message'] ;


    //validate contact fields
    if (!strstr(trim($ _POST['email']),"@"))
    {
    $email_error = "<p class='comment' >please enter your email
    address!</p><br>";
    $contact = "no";
    }

    if ($_POST['name'] == "")
    {
    $name_error = "<p class='comment' >name field is blank!</p><br>";
    $contact = "no";
    }

    if ($_POST['email'] == "")
    {
    $email_error = "<p class='comment' >email field is blank!</p><br>";
    $contact = "no";
    }

    if ($_POST['subject'] == "")
    {
    $subject_error = "<p class='comment' >subject field is
    blank!</p><br>";
    $contact = "no";
    }

    if ($_POST['message'] == "")
    {
    $message_error = "<p class='comment' >message field is
    blank</p><br>";
    $contact = "no";
    }

    if ($contact != "no")
    {

    //if pass, then submit email and redirect to thankyou page
    mail($to, $subject, $message, "From: $name <$email>");
    {
    header("Locatio n: contactsent.htm l");
    exit();
    }


    ?>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Untitl ed Document</title>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <link href="css/jace2.css" rel="stylesheet " type="text/css" />
    </head>

    <body>
    <p class="topic">U nable to send your message!</p><br>

    <?PHP

    //list error(s)
    else if $send == "no");
    {
    echo "$name_erro r";
    echo "$email_err or";
    echo "$subject_error ";
    echo "$message_error ";
    }

    ?>

    <p> Click your browser's &quot;back&quot ; button to return to the
    contact form and fill missing fields.<br>
    </p>
    </body>
    </html>
  • Pedro Graca

    #2
    Re: Contact Form

    Jason wrote:[color=blue]
    > It seems that I get too many parse errors all over and cannot figure
    > went wrong since most of these appears right to me...
    >
    > <?PHP[/color]
    (snip)[color=blue]
    > if ($contact != "no")
    > {[/color]


    You never closed this '{' for the if

    [color=blue]
    > //if pass, then submit email and redirect to thankyou page
    > mail($to, $subject, $message, "From: $name <$email>");
    > {
    > header("Locatio n: contactsent.htm l");
    > exit();
    > }
    >
    >
    > ?>[/color]
    (snip HTML)[color=blue]
    ><?PHP
    >
    > //list error(s)
    > else if $send == "no");[/color]


    This if does not have an '('
    Are you sure you want the if to do nothing?

    if ($send == "no");

    is a complete instruction. The next '{' is *not* part of the if().

    [color=blue]
    > {[/color]
    (snip more code)



    HTH
    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    • Jason

      #3
      Re: Contact Form

      Pedro, thanks for help! I just redefined the script to make it more
      sense and still get parse errors (seem "else" statement is main parse
      error problem):


      <?PHP

      $to = "scoobyood@jace 41.com" ;
      $name = $_POST['name'] ;
      $email = $_POST['email'] ;
      $subject = $_POST['subject'] ;
      $message = $_POST['message'] ;


      ?>

      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <title>Untitl ed Document</title>
      <meta http-equiv="Content-Type" content="text/html;
      charset=iso-8859-1" />
      <link href="css/jace2.css" rel="stylesheet " type="text/css" />
      </head>

      <body>
      <p class="topic">U nable to send your message!</p><br>

      <?PHP

      //Validate all fields
      if (!strstr(trim($ _POST['email']),"@"))
      {
      $email_error = "<p class='comment' >please enter your email
      address!</p><br>";
      $contact = "no";
      }

      if ($_POST['name'] == "")
      {
      $name_error = "<p class='comment' >name field is blank!</p><br>";
      $contact = "no";
      }

      if ($_POST['email'] == "")
      {
      $email_error = "<p class='comment' >email field is blank!</p><br>";
      $contact = "no";
      }

      if ($_POST['subject'] == "")
      {
      $subject_error = "<p class='comment' >subject field is
      blank!</p><br>";
      $contact = "no";
      }

      if ($_POST['message'] == "")
      {
      $message_error = "<p class='comment' >message field is
      blank</p><br>";
      $contact = "no";
      }


      //if form fail, echo error lists and exit script
      if ($contact != "no")
      {
      echo "$name_erro r";
      echo "$email_err or";
      echo "$subject_error ";
      echo "$message_error ";
      {
      exit();
      }


      //if form pass, submit email and redirect to thank you page
      else {
      mail($to, $subject, $message, "From: $name <$email>");
      {
      header("Locatio n: contactsent.htm l");
      exit();
      }


      ?>

      <p> Click your browser's &quot;back&quot ; button to return to the
      contact form and fill missing fields.<br>
      </p>
      </body>
      </html>

      Comment

      • Default User

        #4
        Re: Contact Form

        Jason wrote:[color=blue]
        >
        > Pedro, thanks for help! I just redefined the script to make it more
        > sense and still get parse errors (seem "else" statement is main parse
        > error problem):[/color]
        [color=blue]
        > //if form fail, echo error lists and exit script
        > if ($contact != "no")
        > {
        > echo "$name_erro r";
        > echo "$email_err or";
        > echo "$subject_error ";
        > echo "$message_error ";
        > {
        > exit();
        > }[/color]

        Take a look at the brackets. How opening, how many closing? How many
        should there be.
        [color=blue]
        > //if form pass, submit email and redirect to thank you page
        > else {
        > mail($to, $subject, $message, "From: $name <$email>");
        > {
        > header("Locatio n: contactsent.htm l");
        > exit();
        > }[/color]

        Once again, look at the brackets.

        This is not difficult stuff. You are obviously not going over your code
        carefully. Use a consistent indentation style and examine your code when
        parse problems occur. Don't worry about the number of them, a misplaced
        bracket or paren will often cause multiple errors.






        Brian Rodenborn

        Comment

        • Geoff Berrow

          #5
          Re: Contact Form

          I noticed that Message-ID:
          <ed5ca32c.04031 91017.1ef2714e@ posting.google. com> from Jason contained
          the following:
          [color=blue]
          >else {
          > mail($to, $subject, $message, "From: $name <$email>");
          > {
          > header("Locatio n: contactsent.htm l");
          > exit();
          > }[/color]


          Missing }
          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • Filth

            #6
            Re: Contact Form

            try using a program that number the lines so you can see the number of each
            line (PHPEdit for example) When php shows an error message it will tell you
            on what line the error occured it is ussually the case that it is right or
            that it is a line before (in such cases where a ; is missing)


            Comment

            • Jason

              #7
              Re: Contact Form

              Really appreciate help and sure leanred php alot in one week! I
              managed to get contact form to work but still having some trouble with
              eregi (validate email addy with "@") and header to redirect to
              thankyou page. I tried full header addy and various tricks but no
              avail and suspect it's due to "echo" above the header script. As for
              eregi, it failed to validate email with "@". Any idea??


              <?PHP

              $to = "scoobyood@jace 41.com" ;
              $name = $_POST['name'] ;
              $email = $_POST['email'] ;
              $subject = $_POST['subject'] ;
              $message = $_POST['message'] ;
              $undelivery = "";

              ?>


              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
              <title>Untitl ed Document</title>
              <meta http-equiv="Content-Type" content="text/html;
              charset=iso-8859-1" />

              <link href="css/jace2.css" rel="stylesheet " type="text/css" />
              </head>

              <body>

              <?PHP

              // validate the email with "@"
              if(!eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3})?)$',
              $email))
              $undelivery ."<span class=\"comment \">email's invalid!</span><br>";

              // validate the email
              if (!$_POST['email'])
              $undelivery .= "<span class=\"comment \">email field's
              empty!</span><br>";

              // validate the name
              if (!$_POST['name'])
              $undelivery .= "<span class=\"comment \">name field's
              empty!</span><br>";

              // validate the subject
              if (!$_POST['subject'])
              $undelivery .= "<span class=\"comment \">subject field's
              empty!</span><br>";

              // validate the message
              if (!$_POST['message'])
              $undelivery .= "<span class=\"comment \">message field's
              empty!</span><br>";

              // display error lists
              if ($undelivery)
              echo $undelivery;

              else {
              // if pass, then email form and redirect to thank you page
              mail($to, $subject, $message,"From: $name <$email>");

              header("Locatio n: contactsent.htm l");

              }
              ?>
              </body>
              </html>
              ..

              Comment

              • Filth

                #8
                Re: Contact Form

                > As for[color=blue]
                > eregi, it failed to validate email with "@". Any idea??[/color]

                I validate emails using the folowing, there is a couple of missing
                characters however as + can also be used in the first part of an email
                address

                !eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",
                $_POST['email'])


                Comment

                • Tim Van Wassenhove

                  #9
                  Re: Contact Form

                  On 2004-03-22, Filth <p.macdonald@bl ueyonder.co.uk> wrote:[color=blue][color=green]
                  >> As for
                  >> eregi, it failed to validate email with "@". Any idea??[/color]
                  >
                  > I validate emails using the folowing, there is a couple of missing
                  > characters however as + can also be used in the first part of an email
                  > address
                  >
                  > !eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",
                  > $_POST['email'])[/color]

                  Do a google search for "rfc822 regular expression".
                  And at phpclasses.org there is a mail validation class too.

                  --

                  Comment

                  • Jason

                    #10
                    Re: Contact Form

                    "Filth" <p.macdonald@bl ueyonder.co.uk> wrote in message news:<QMz7c.830 $uM6.505@news-binary.blueyond er.co.uk>...[color=blue][color=green]
                    > > As for
                    > > eregi, it failed to validate email with "@". Any idea??[/color]
                    >
                    > I validate emails using the folowing, there is a couple of missing
                    > characters however as + can also be used in the first part of an email
                    > address
                    >
                    > !eregi("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",
                    > $_POST['email'])[/color]


                    I tried your ereg and it still doesn't working. I also tried another
                    ereg scripts I came across in internet and all seem won't work too. I
                    might miss something. As for phpclasses.org, I'll look into it later
                    when I have time...Thanks for help and tips!

                    Jace

                    Comment

                    Working...