1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Contact form - blank message, from form content

Discussion in 'HTML & Website Design' started by lionet, Jun 6, 2015.

  1. #1
    Hello,

    I'm trying to figurate how can I solve this problem with my contact form, whenever I click submit button on my form contact, in my mail I receiving only three correct fields, rest of them (such as message, and 2 other input box - are blank).

    My code:
    <form class="form" action=process.php method=POST>
    <p class="name">
    <input type="text" name="name" id="name" placeholder="Your Name" />
        <label for="name"></label></p>
    <p class="name">
    <input name="phone" id="phone" placeholder="Phone Number" />
    <label for="name"></label></p>
    <p class="email">
    <input type="text" name="email" id="email" placeholder="Your Email" />
    <label for="email"></label></p>
    <p class="web">
    <input type="text" name="web" id="web" placeholder="Your Website" />
    <label for="web"></label></p>
    <p class="text">
    <textarea class="text2" name="wya" id="infos"  placeholder="Who You Are?"></textarea></p>
    <p class="text">
    <textarea class="text3" name="colours" id="colours" placeholder="Your 3 favourite colours"></textarea></p>
    <p class="text"><textarea name="text" name="message" placeholder="Message"></textarea></p>
    <div class=g-recaptcha data-sitekey=6LdTGAUTAAAAAF6Z_7sqbHSzGdbNDv1hFHZIdbKp></div>
          
    <p class="submit">
                <input type="submit" value="Send" />
            </p>
        </form>
    HTML:
    <?php
            $captcha;
      if(isset($_POST['g-recaptcha-response'])){
           $captcha=$_POST['g-recaptcha-response'];
         }
      if(!$captcha){
          echo '<h2>Please check the the captcha form.</h2>';
           exit;
       }
    
      $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=CODE CAPTCHA =".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    
      if($response.success==false){
              header("Location: http://www.lionet.ie/antispam.html");
      }
      else{
    
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $web = $_POST['web'];
    $infos = $_POST['infos'];
    $colours = $_POST['colours'];
    $message = $_POST['message'];
    $formcontent="Client Name:$name\n Contact Number:$phone \n E-Mail:$email \n Website:$message";
    
    $recipient = "mymail";
    $subject = "New Clients question";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    header("Location: http://www.lionet.ie/thanks.html");
      }
    ?>
    PHP:
    Please help.
     
    Solved! View solution.
    lionet, Jun 6, 2015 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    You have two "name" properties in your message textarea:
    <textarea name="text" name="message" 
    Code (markup):
    & these
    
    $web = $_POST['web'];
    $infos = $_POST['infos'];
    $colours = $_POST['colours'];
    Code (markup):
    aren't included anywhere in your code to be sent in the email.
     
    papa_face, Jun 6, 2015 IP
  3. lionet

    lionet Member

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    33
    #3
    Thanks for reply. however still don't get it, does name and id property must be the same in POST and php code? for example
    "<input type="text" name="web" id="web" placeholder="Your Website" />"
    "$web = $_POST['web'];"
     
    lionet, Jun 6, 2015 IP
  4. #4
    Change your HTML to
    
    <form class="form" action=process.php method=POST>
    <p class="name">
    <input type="text" name="name" id="name" placeholder="Your Name" />
        <label for="name"></label></p>
    <p class="name">
    <input name="phone" id="phone" placeholder="Phone Number" />
    <label for="name"></label></p>
    <p class="email">
    <input type="text" name="email" id="email" placeholder="Your Email" />
    <label for="email"></label></p>
    <p class="web">
    <input type="text" name="web" id="web" placeholder="Your Website" />
    <label for="web"></label></p>
    <p class="text">
    <textarea class="text2" name="wya" id="infos"  placeholder="Who You Are?"></textarea></p>
    <p class="text">
    <textarea class="text3" name="colours" id="colours" placeholder="Your 3 favourite colours"></textarea></p>
    <p class="text"><textarea name="message" placeholder="Message"></textarea></p>
    <div class=g-recaptcha data-sitekey=6LdTGAUTAAAAAF6Z_7sqbHSzGdbNDv1hFHZIdbKp></div>
         
    <p class="submit">
                <input type="submit" value="Send" />
            </p>
        </form>
    Code (markup):
    and your PHP code to:
    
    <?php
            $captcha;
      if(isset($_POST['g-recaptcha-response'])){
           $captcha=$_POST['g-recaptcha-response'];
         }
      if(!$captcha){
          echo '<h2>Please check the the captcha form.</h2>';
           exit;
       }
    
      $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=CODE CAPTCHA =".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    
      if($response.success==false){
              header("Location: http://www.lionet.ie/antispam.html");
      }
      else{
    
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $email = $_POST['email'];
    $web = $_POST['web'];
    $infos = $_POST['infos'];
    $colours = $_POST['colours'];
    $message = $_POST['message'];
    $formcontent="Client Name:$name\n Contact Number:$phone \n E-Mail:$email \n Colours:$colours \n Infos:$infos \n Web:$web  \n Website:$message";
    
    $recipient = "mymail";
    $subject = "New Clients question";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    header("Location: http://www.lionet.ie/thanks.html");
      }
    ?>
    Code (markup):
     
    papa_face, Jun 6, 2015 IP
  5. lionet

    lionet Member

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    33
    #5
    Everything works great, I got it, the name and id has to be the same like in php, thank you so much papa!

    Also, on my mail I'm getting as new email "." symbol only (in thread area) how can I solve this?
     
    lionet, Jun 6, 2015 IP
  6. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #6
    Sorry i'm not sure what you mean by the last bit, can you elaborate further?
     
    papa_face, Jun 6, 2015 IP
  7. lionet

    lionet Member

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    33
    #7
    When I'm opening my email, after submitted message, I'm getting only "." in thread (however everything works correct)

    [​IMG]
     
    lionet, Jun 6, 2015 IP
  8. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #8
    Try changing
    $mailheader = "From: $email \r\n";
    Code (markup):
    to
    
    $mailheader = "From: $email <$email>";
    
    Code (markup):
    Not sure if that'll work.
     
    papa_face, Jun 6, 2015 IP
  9. lionet

    lionet Member

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    33
    #9
    Works, thank you so much mate, have a nice day ! :)
     
    lionet, Jun 6, 2015 IP
    papa_face likes this.
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Btw - ID and name does NOT have to be the same - but $_POST only cares about the name-attribute. The ID can be whatever you want it to be. (Although it's often easier to just use the same ID and name)
     
    PoPSiCLe, Jun 6, 2015 IP
  11. lionet

    lionet Member

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    33
    #11
    Thank you all for response. Cheers :)
     
    lionet, Jun 6, 2015 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #12
    Just a side note, might help cut down on the code bloat and punch up your semantics. First stop calling labels and their inputs "paragraphs" -- they aren't. Would also be nice if your labels ACTUALLY had content and you weren't misusing and outright abusing PLACEHOLDER.

    http://www.pardot.com/faqs/forms/placeholders-and-labels/
    http://www.webaxe.org/placeholder-attribute-is-not-a-label/
    http://baymard.com/blog/false-simplicity

    Even the HTML 5 specification says it.... and I quote:
    "The placeholder attribute should not be used as a replacement for a label."
    http://www.w3.org/TR/html5/forms.html#the-placeholder-attribute

    I'm increasingly shocked that people can get this far into building a page in terms of HTML and back-side code like PHP, but still not manage to have learned how to use HTML properly.

    NOT really related to your problem (of not using 'names' set the markup while using 'names' that arent), but that form is such a poorly written inaccessible mess I thought it should at least be mentioned.
     
    Last edited: Jun 7, 2015
    deathshadow, Jun 6, 2015 IP