Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.43 KB | None | 0 0
  1.         if($hasForm){
  2.             $template_header .= '
  3.                
  4.                 <?php
  5.                 if(isset($_POST["check"])){
  6.  
  7.                     '.$formInputsCode.'
  8.  
  9.                     '.$formMessagesCode.'
  10.  
  11.                     '.$formSettingsCode.'
  12.  
  13.                     print \'<script "text/javascript">
  14.  
  15.                     $(function() {\';
  16.  
  17.  
  18.  
  19.                         $isset_errors = "";
  20.                         $hasEmail     = false;
  21.                         $hasCaptcha   = false;
  22.                         foreach($formInputs as $input){
  23.                             if(isset($_POST["form-field-" . $input]) && !empty($_POST["form-field-" . $input])){
  24.                                 $isset_errors .= 0;
  25.                                 print  \'
  26.                                 $("#form-field-"+"\'.$input.\'").val("\'.$_POST["form-field-" . $input].\'");
  27.                                 \';
  28.  
  29.                                 // checking if the email fields exists
  30.                                 if("form-field-" . $input == "form-field-email"){
  31.  
  32.                                     $hasEmail = true;
  33.  
  34.                                 }
  35.  
  36.                                 //checking if the captcha field exists
  37.                                 if("form-field-" . $input == "form-field-captcha"){
  38.                                    
  39.                                     $hasCaptcha = true;
  40.  
  41.                                 }
  42.  
  43.                             }
  44.                             else{
  45.                                 $isset_errors .= 1;
  46.                                 print  \'
  47.                                 $("#form-field-"+"\'.$input.\'").addClass("error");
  48.                                 \';
  49.                             }
  50.                         }
  51.  
  52.                         // Checking for errors
  53.  
  54.                         if(is_int(strpos($isset_errors,"1"))){
  55.                             print  \'
  56.                             $("#form-messages").html("<p class=\"text-danger\">\'.$formMessages[0].\'</p>")
  57.                             \';
  58.                         }
  59.                         else{
  60.  
  61.                             $errors = "";
  62.  
  63.                             if($hasEmail == true){
  64.  
  65.                                 $email = (string)$_POST["form-field-email"];
  66.                                 if(preg_match(\'/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/\',$email)){
  67.                                     $errors .= "0";
  68.                                 }
  69.                                 else{
  70.                                     $errors .= "1";
  71.                                     print  \'
  72.                                     $("#form-messages").append("<p class=\"text-danger\">\'.$formMessages[1].\'</p>")
  73.                                     \';
  74.                                 }
  75.  
  76.                             }
  77.  
  78.                             if($hasCaptcha == true){
  79.  
  80.                                 if($_SESSION["captcha"] == $_POST["form-field-captcha"]){
  81.                                     $errors .= "0";
  82.                                 }
  83.                                 else{
  84.                                     $errors .= "1";
  85.                                     print  \'
  86.                                     $("#form-messages").append("<p class=\"text-danger\">\'.$formMessages[2].\'</p>")
  87.                                     \';
  88.                                 }
  89.  
  90.                             }
  91.  
  92.                             if(!is_int(strpos($errors,"1"))){
  93.  
  94.                                     print  \'
  95.                                     $("#form-messages").html("<p class=\"text-success\">\'.$formMessages[3].\'</p>")
  96.                                     \';
  97.  
  98.  
  99.                                     //
  100.                                     // Iar aici trimitem mailul
  101.                                     //
  102.  
  103.                                     if(isset($_POST["form-field-name"]) && !empty($_POST["form-field-name"]) ){
  104.                                         $name = $_POST["form-field-name"];
  105.                                     }
  106.                                     else{
  107.                                         $name = "(None)";
  108.                                     }
  109.                                     if(isset($_POST["form-field-email"]) && !empty($_POST["form-field-email"]) ){
  110.                                         $mail = $_POST["form-field-email"];
  111.                                     }
  112.                                     else{
  113.                                         $mail = "(None)";
  114.                                     }
  115.                                     if(isset($_POST["form-field-subject"]) && !empty($_POST["form-field-subject"]) ){
  116.                                         $emailsubject = $_POST["form-field-subject"];
  117.                                     }
  118.                                     else{
  119.                                         $emailsubject = "(None)";
  120.                                     }
  121.  
  122.                                     $to = $formSettings[1];
  123.                                     $subject = "['.$metaTitle.' Contact] ";
  124.  
  125.                                     $message = "Name: " . $name . "\r\n";
  126.                                     $message .= "Email: " . $mail . "\r\n";
  127.                                     $message .= "Subject: " . $emailsubject . "\r\n";
  128.  
  129.                                     $headers = "From: ".$formSettings[0];
  130.  
  131.                                     mail($to,$subject,$message,$headers);
  132.  
  133.                             }
  134.                         }
  135.  
  136.                        
  137.  
  138.                     print \'});
  139.  
  140.                     </script>\';
  141.                 }
  142.                 ?>
  143.  
  144.                 ';
  145.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement