Advertisement
Guest User

Mon formulaire de contact

a guest
Apr 11th, 2012
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.72 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Contact
  4. */
  5. ?>
  6.  
  7. <!--Début formulaire 1/2-->
  8. <?php
  9. //If the form is submitted
  10. if(isset($_POST['submitted'])) {
  11.  
  12.     //Check to see if the honeypot captcha field was filled in
  13.     if(trim($_POST['checking']) !== '') {
  14.         $captchaError = true;
  15.     } else {
  16.    
  17.         //Check to make sure that the name field is not empty
  18.         if(trim($_POST['contactName']) === '') {
  19.             $nameError = 'You forgot to enter your name.';
  20.             $hasError = true;
  21.         } else {
  22.             $name = trim($_POST['contactName']);
  23.         }
  24.        
  25.         //Check to make sure sure that a valid email address is submitted
  26.         if(trim($_POST['email']) === '')  {
  27.             $emailError = 'You forgot to enter your email address.';
  28.             $hasError = true;
  29.         } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  30.             $emailError = 'You entered an invalid email address.';
  31.             $hasError = true;
  32.         } else {
  33.             $email = trim($_POST['email']);
  34.         }
  35.            
  36.         //Check to make sure comments were entered 
  37.         if(trim($_POST['comments']) === '') {
  38.             $commentError = 'You forgot to enter your comments.';
  39.             $hasError = true;
  40.         } else {
  41.             if(function_exists('stripslashes')) {
  42.                 $comments = stripslashes(trim($_POST['comments']));
  43.             } else {
  44.                 $comments = trim($_POST['comments']);
  45.             }
  46.         }
  47.            
  48.         //If there is no error, send the email
  49.         if(!isset($hasError)) {
  50.  
  51.             $emailTo = 'soykje@soykje.com';
  52.             $subject = 'Message de '.$name.', envoyé depuis www.soykje.com';
  53.             $sendCopy = trim($_POST['sendCopy']);
  54.             $body = "Nom: $name \nEmail: $email \n\nMessage: $comments";
  55.             $headers = 'From: www.soykje.com <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  56.            
  57.             mail($emailTo, $subject, $body, $headers);
  58.  
  59.             if($sendCopy == true) {
  60.                 $subject = 'You emailed Your Name';
  61.                 $headers = 'From: Your Name <noreply@somedomain.com>';
  62.                 mail($email, $subject, $body, $headers);
  63.             }
  64.  
  65.             $emailSent = true;
  66.  
  67.         }
  68.     }
  69. } ?>
  70. <!--Fin formulaire 1/2-->
  71.  
  72. <?php get_header(); ?>
  73. <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/contact-form.js"></script>
  74.  
  75. <ul class="categoryfilter"></ul>
  76. <div id="content">
  77. <ul id="content-contact">
  78.     <li class="post_contact">
  79.     <?php if(isset($emailSent) && $emailSent == true) { ?>
  80.         <p class="thanks">Merci !</p>
  81.         <?php } else { ?>
  82.         <p>Que ce soit pour une question, un projet, ou tout simplement pour dire bonjour, n'h&eacute;sitez pas &agrave; me contacter...</p>
  83.         <?php } ?>
  84.     </li>
  85.            
  86.     <li class="formulaire">
  87.     <form action="<?php the_permalink(); ?>" id="contactForm" method="post"><!--Début formulaire 2/2-->
  88.    
  89.         <div class="nom"><label for="contactName">votre nom</label>
  90.         <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />
  91.         <?php if($nameError != '') { ?>
  92.         <span class="error"><?=$nameError;?></span>
  93.         <?php } ?>
  94.         </div>
  95.                
  96.         <div class="adresse"><label for="email">votre email</label>
  97.         <input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="requiredField email" />
  98.         <?php if($emailError != '') { ?>
  99.         <span class="error"><?=$emailError;?></span>
  100.         <?php } ?>
  101.         </div>
  102.                
  103.         <div class="textarea"><label for="commentsText">votre message</label>
  104.         <textarea name="comments" id="commentsText" rows="20" cols="30" class="requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
  105.         <?php if($commentError != '') { ?>
  106.         <span class="error"><?=$commentError;?></span>
  107.         <?php } ?>
  108.         </div>
  109.        
  110.         <div class="screenReader"><input type="text" name="checking" id="checking" class="screenReader" value="<?php if(isset($_POST['checking']))  echo $_POST['checking'];?>" /><label for="checking" class="screenReader">Si vous n'êtes pas un robot, laissez ce champ vide.</label></div>
  111.         <div class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" /><button type="submit">envoyer</button></div>
  112.        
  113.     </form>
  114.     </li><!--Fin formulaire 2/2-->
  115.    
  116.     <li class="getpdf">
  117.         <p>...vous pouvez aussi t&eacute;l&eacute;charger mon book !</p>
  118.         <a href="<?php bloginfo('template_url'); ?>/images/booksoykje.pdf" title="T&eacute;l&eacute;charger mon book"><div id="pdf"><img src="<?php bloginfo('template_url'); ?>/images/pdf.png" /></div></a>
  119.     </li>
  120.            
  121.     <li class="profil">
  122.         <div id="gmap"></div>
  123.         <p>SOYKJE | J Paul LESCOUZ&Egrave;RES<br/>76 rue du Bournard<br/>92700 Colombes, FR</p>
  124.     </li>
  125.    
  126. </ul>
  127. </div>
  128.  
  129. <!--?php get_sidebar1(); ?>-->
  130. <?php get_footer(); ?>
  131. </div>
  132. </body>
  133. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement