SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no luck with contact forms, help me.

    Anyone have any good tips for up to date complete contact forms with validation and everything that is easy to implement?

    ATM my form looks like this, no validation.

    Code HTML4Strict:
    <form id="contact-form" action="email.php" method="post">
    	<div class="input-wrapper1">
    		<label for="name">namn</label><input type="text" name="name" id="name" />
    	</div>
    	<div class="input-wrapper2">
    		<label for="mail">epost</label><input  type="text" name="mail" id="mail" />
    	</div>
    	<label for="msg">ärende</label><textarea name="msg" id="msg"></textarea>
    	<button type="submit" name="send" id="send"><i <i class="icon-angle-circled-right"></i></button>
    </form>

    Code PHP:
    <?php 
     
    $name = $_POST['name'];
    $mail = $_POST['mail'];
    $msg = $_POST['msg'];
    $formcontent="From: $name \n Mail: $mail \n Message: $msg";
    $recipient = "mail@outlook.com";
    $subject = "Contactform submit from RB";
    $mailheader = "From: $mail \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Thank You!";
     
    ?>

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,657
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Here is how I do it with server and client side validation. http://www.websitecodetutorials.com/...validation.php. Works perfect.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    Here is how I do it with server and client side validation. http://www.websitecodetutorials.com/...validation.php. Works perfect.
    thx alot. will give it a try.

  4. #4
    SitePoint Member belansus's Avatar
    Join Date
    Aug 2013
    Location
    Newcastle
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a lot to remember when adding validation to inputs to your website. If your wanting to use a fully implemented validation procedure I would suggest using a framework like Codeignighter. I'd also stick some form of Captcha field into your form, helps stop spammers firing off a million and one emails from your server. Good luck!

  5. #5
    Grüße aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by ReGGaeBOSS View Post
    Code PHP:
    <?php 
     
    $name = $_POST['name'];
    $mail = $_POST['mail'];
    $msg = $_POST['msg'];
    $formcontent="From: $name \n Mail: $mail \n Message: $msg";
    $recipient = "mail@outlook.com";
    $subject = "Contactform submit from RB";
    $mailheader = "From: $mail \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Thank You!";
    ?>
    It should probably be mentioned that the above code doesn't apply any kind of validation to what is passed to the mail function.
    This means that you could potentially insert additional headers and use the contact form as a spam tool.

    You can read more here: http://www.securephpwiki.com/index.php/Email_Injection

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,657
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    no luck with contact forms, help me.

    Mine accounts for headers and etc. I pieced it together a long while back. Quite happy with it. Form processing is probably the hardest thing I've ever done to get right. Usually if you grab some one piece of code it has like 10 pages of mumbo jumbo. I was never ok with that. I needed to know what it was doing.


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
  •