Results 1 to 6 of 6

Thread: 'contact me' page

  1. #1
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 'contact me' page

    i wrote a 'contact me' page through which ppl can contact me if they wish. i want to make sure tht if the user doesn't fill anyone of the required fields, red text will appear will appear underneath the fields telling the user to fill them in. and can someone also tell me if i have done anything wrong in the code? the code is given below:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <link rel="stylesheet" href="style.css" type="text/css" />
    <body>
    <?php
    $name = $_POST['name']; 
    $sub = $_POST['sub']; 
    $address = $_POST['email']; 
    $msg = $_POST['msg']; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $mess = " 
    Subject: $sub \n 
    Message: $msg \n 
    From: $address \n 
    IP: $ip \n 
    "; 
    if ( (!$name)||(!$sub)||(!$msg) ){ 
    echo "Please fix the following:<BR>"; 
    
    if(!$name){ 
    echo "Please fill in your name<BR>"; 
    } 
    if(!$sub){ 
    echo "Please fill in the subject<BR>"; 
    } 
    if(!$msg){ 
    echo "Please fill in the message<BR><BR>"; 
    } 
    echo('
    <form action="contact.php" method="post"> 
    Name: <input type="text" name="name" class="input"><BR> 
    Subject: <input type="text" name="sub" class="input"><BR> 
    E-mail <input type="text" name="email" class="input"><BR> 
    Message: 
    <textarea name="msg" rows="7" cols="50" class="input"></textarea> 
    <input type="submit" value="Send" class="button"> 
    </form>"; 
    } else { 
    
    mail("myaddress@mydomain.com", "Subject: $sub", $mess, "From: $name <$address>"); 
    if(mail) { 
    echo "Thank you! Please wait up to 48 hours for a reply."; 
    }  else  { 
    echo "The message could not be sent. Please try again later."; 
    } 
    }  
    ?>');
    </body></html>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The only things I could see by just glancing at the code is below in red. You will also be able to see one other problem that I took out by comparing the codes.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <link rel="stylesheet" href="style.css" type="text/css" />
    <body>
    <?php
    $name = $_POST['name']; 
    $sub = $_POST['sub']; 
    $address = $_POST['email']; 
    $msg = $_POST['msg']; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $mess = " 
    Subject: $sub \n 
    Message: $msg \n 
    From: $address \n 
    IP: $ip \n 
    "; 
    if ( (!$name)||(!$sub)||(!$msg) ){ 
    echo "Please fix the following:<BR>"; 
    
    if(!$name){ 
    echo "Please fill in your name<BR>"; 
    } 
    if(!$sub){ 
    echo "Please fill in the subject<BR>"; 
    } 
    if(!$msg){ 
    echo "Please fill in the message<BR><BR>"; 
    } 
    echo('
    <form action="contact.php" method="post"> 
    Name: <input type="text" name="name" class="input"><BR> 
    Subject: <input type="text" name="sub" class="input"><BR> 
    E-mail <input type="text" name="email" class="input"><BR> 
    Message: 
    <textarea name="msg" rows="7" cols="50" class="input"></textarea> 
    <input type="submit" value="Send" class="button"> 
    </form>'); 
    
    } else { 
    
    mail("myaddress@mydomain.com", "Subject: $sub", $mess, "From: $name <$address>"); 
    
    if(mail) { 
    echo "Thank you! Please wait up to 48 hours for a reply."; 
    }  else  { 
    echo "The message could not be sent. Please try again later."; 
    } 
    }  
    ?>
    
    </body>
    </html>
    Hope this helps.

  3. #3
    Join Date
    Feb 2006
    Posts
    230
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    You probably want to use sessions. Then transfer your input data to sessions variables so that if there is an incomplete entry, you can set error messages to instruct what to fill in and fill the fields with the previous data input so the user doesn't have to retype everything. And then you cause the program to redirect to itself if there is an incomplete entry, else send the data and announce that its been sent. You can use a hidden variable so you can test if the data is complete on reentry to finish.

    Use functions to generate the basic parts of the html code you need and it will simplify the understanding of the flow.

    That's the way I do it, and it looks great.

  4. #4
    Join Date
    Oct 2006
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Strangeplant View Post
    You probably want to use sessions. Then transfer your input data to sessions variables so that if there is an incomplete entry, you can set error messages to instruct what to fill in and fill the fields with the previous data input so the user doesn't have to retype everything. And then you cause the program to redirect to itself if there is an incomplete entry, else send the data and announce that its been sent. You can use a hidden variable so you can test if the data is complete on reentry to finish.

    Use functions to generate the basic parts of the html code you need and it will simplify the understanding of the flow.

    That's the way I do it, and it looks great.

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    When test pointed out that code, he meant that echo isn't a bracket function, see here:
    Code:
    echo '
    <form action="contact.php" method="post"> 
    Name: <input type="text" name="name" class="input"><BR> 
    Subject: <input type="text" name="sub" class="input"><BR> 
    E-mail <input type="text" name="email" class="input"><BR> 
    Message: 
    <textarea name="msg" rows="7" cols="50" class="input"></textarea> 
    <input type="submit" value="Send" class="button"> 
    </form> ';
    It stands alone, without brackets. As for what StrangePlant said, all he/she meant was that the data could be stored in sessions and validated.
    - Mike

  6. #6
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    this is the way you code should look like. You were not careful with the syntaxes used. Differenciate this with yours

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <link rel="stylesheet" href="style.css" type="text/css" />
    <body>
    PHP Code:
    <?php
    $name 
    $_POST['name']; 
    $sub $_POST['sub']; 
    $address $_POST['email']; 
    $msg $_POST['msg']; 
    $ip $_SERVER['REMOTE_ADDR']; 
    $mess 
    Subject: 
    $sub \n 
    Message: 
    $msg \n 
    From: 
    $address \n 
    IP: 
    $ip \n 
    "

    if ( (!
    $name)||(!$sub)||(!$msg) ){ 
        echo 
    "Please fix the following:<BR>"


    if(!
    $name){ 
        echo 
    "Please fill in your name<BR>"
    }
     
    if(!
    $sub){ 
        echo 
    "Please fill in the subject<BR>"

    if(!
    $msg){ 
        echo 
    "Please fill in the message<BR><BR>"

    echo(
    '
    <form action="contact.php" method="post"> 
    Name: <input type="text" name="name" class="input"><BR> 
    Subject: <input type="text" name="sub" class="input"><BR> 
    E-mail <input type="text" name="email" class="input"><BR> 
    Message: 
    <textarea name="msg" rows="7" cols="50" class="input"></textarea> 
    <input type="submit" value="Send" class="button"> 
    </form>'
    ); 
    } else { 

    mail("myaddress@mydomain.com""Subject: $sub"$mess"From: $name <$address>"); 
    if(
    mail) { 
    echo 
    "Thank you! Please wait up to 48 hours for a reply."
    }  else  { 
    echo 
    "The message could not be sent. Please try again later."

    }  
    ?>
    HTML Code:
    </body></html>

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
  •