Advertisement
lalatino

the form example for Execute PHP plugin

Aug 4th, 2012
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // script example to be pasted to ExecutePHP plugin's section, for this topic: http://gpeasy.com/Special_Forum?show=t920
  2.  
  3. global $page,$config,$langmessage,$title, $dataDir;
  4. $addon_key = gpPlugin::AddonFromId(62);
  5. $addonPathCode = $dataDir.'/data/_addoncode/'.$addon_key;
  6. $addonPathData = $dataDir.'/data/_addondata/'.$addon_key;
  7. $addonRelativeCode = common::GetDir('/data/_addoncode/'.$addon_key);
  8. $addonRelativeData = common::GetDir('/data/_addondata/'.$addon_key);
  9.  
  10. echo '<script src="'.$addonRelativeCode.'/form_validator.min.js" type="text/javascript"></script>
  11. <script type="text/javascript"> var RecaptchaOptions = { lang : '; echo common::ConfigValue('recaptcha_language',''); echo '\', theme : \'red\' }; </script>';
  12.  
  13.  $rhc_string='Antispam test passed!'; // REVERSE HONEYPOT CAPTCHA OK STRING ~ Antispam test passed! Humanity confirmed! :-)
  14.  if (file_exists($addonPathData.'/scf_style.css'))
  15.   $page->css_user[] = $addonRelativeData.'/scf_style.css';
  16.  else
  17.   $page->css_user[] = $addonRelativeCode.'/scf_style.css';
  18. echo '
  19. <div class="simplecontactform">
  20. <noscript><p>Unfortunately, JavaScript is currently disabled by this browser. Please enable JavaScript for full functionality.</p></noscript>';
  21.  
  22. if (isset($_POST["submitForm"]) && $_POST["url"]=='') {
  23.  require_once($addonPathCode.'/class.phpmailer.php');
  24.  $mail = new PHPMailer();
  25.  $mail->SetLanguage("sk");
  26.  $mail->IsHTML(false);
  27.  $mail->WordWrap = 50;
  28.  $mail->CharSet = "utf-8";
  29.  $mail->IsSMTP();
  30.  $mail->SMTPDebug = false;
  31.  $mail->SMTPAuth = true;
  32.  $mail->SMTPSecure="ssl";
  33.  $mail->Host="smtp.gmail.com";
  34.  $mail->Port="465";
  35.  $mail->Username=$config['smtp_user'];
  36.  $mail->Password=$config['smtp_pass'];
  37.  echo '<i>Your data that will be posted in the email:</i><br/>';
  38.  echo '<b>Your name:</b> ';
  39.  if (isset($_POST['item1']))
  40.  {
  41.   echo $_POST['item1'].'<br/>';
  42.  }
  43.  else
  44.   echo '-<br/>';
  45.  echo '<b>Your phone:</b> ';
  46.  if (isset($_POST['item2']))
  47.  {
  48.   echo $_POST['item2'].'<br/>';
  49.  }
  50.  else
  51.   echo '-<br/>';
  52.  echo '<b>Your e-mail:</b> ';
  53.  if (isset($_POST['item3']))
  54.  {
  55.   echo $_POST['item3'].'<br/>';
  56.  }
  57.  else
  58.   echo '-<br/>';
  59.  echo '<b>Subject:</b> ';
  60.  if (isset($_POST['item4']))
  61.  {
  62.   echo $_POST['item4'].'<br/>';
  63.  }
  64.  else
  65.   echo '-<br/>';
  66.  echo '<b>Message:</b> ';
  67.  if (isset($_POST['item5']))
  68.  {
  69.   echo $_POST['item5'].'<br/>';
  70.  }
  71.  else
  72.   echo '-<br/>';
  73.  echo '<b>file attachment:</b> ';
  74.  if ($_FILES['item6']['name']!='')
  75.   echo '<i>'.$_FILES['item6']['name'].'</i>';
  76.  else
  77.   echo '-';
  78.  if ($_FILES['item6']['error']!=0 && $_FILES['item6']['error']!=4)
  79.   echo ' <i>error</i> <a href="http://php.net/manual/en/features.file-upload.errors.php" target="_blank">'.$_FILES['item6']['error'].'</a>';
  80.  echo ' <br/>';
  81.  
  82.  
  83.  $send = true;
  84.  if (!isset($_POST["item1"]) || $_POST["item1"]=='')
  85.  {
  86.   printf($langmessage['OOPS_REQUIRED'],'Your name');
  87.   echo '<br/>';
  88.   $send = false;
  89.  }
  90.  if (!isset($_POST["item3"]) || $_POST["item3"]==''
  91.   || !preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $_POST["item3"]))
  92.  {
  93.   echo $langmessage['invalid_email'].'<br/>';
  94.   $send = false;
  95.  }
  96.  if (!isset($_POST["item4"]) || $_POST["item4"]=='')
  97.  {
  98.   printf($langmessage['OOPS_REQUIRED'],'Subject');
  99.   echo '<br/>';
  100.   $send = false;
  101.  }
  102.  if (!isset($_POST["item5"]) || $_POST["item5"]=='')
  103.  {
  104.   printf($langmessage['OOPS_REQUIRED'],'Message');
  105.   echo '<br/>';
  106.   $send = false;
  107.  }
  108.  if (!$send)
  109.  {
  110.   echo '<br/><b>Message not sent. Please correct invalid fields and try again.</b> <a href="'.common::GetUrl($title).'" target="_blank">'.common::GetLabel($title).'</a></div>';
  111.   return;
  112.  }
  113.  $_name = $_POST["item1"];
  114.  $_email = $_POST["item3"];
  115.  $_subject = $_POST["item4"];
  116.  $_message = $_POST["item5"];
  117.  $_body = '';
  118.  
  119.  
  120.     $_body .= 'Your name'.': ';
  121.     if (isset($_POST['item1']))
  122.     {
  123.         $_body .= $_POST['item1'].PHP_EOL.PHP_EOL;
  124.     }
  125.     else
  126.         $_body .= '-'.PHP_EOL.PHP_EOL;
  127.     $_body .= 'Your phone'.': ';
  128.     if (isset($_POST['item2']))
  129.     {
  130.         $_body .= $_POST['item2'].PHP_EOL.PHP_EOL;
  131.     }
  132.     else
  133.         $_body .= '-'.PHP_EOL.PHP_EOL;
  134.     $_body .= 'Your e-mail'.': ';
  135.     if (isset($_POST['item3']))
  136.     {
  137.         $_body .= $_POST['item3'].PHP_EOL.PHP_EOL;
  138.     }
  139.     else
  140.         $_body .= '-'.PHP_EOL.PHP_EOL;
  141.     $_body .= 'Subject'.': ';
  142.     if (isset($_POST['item4']))
  143.     {
  144.         $_body .= $_POST['item4'].PHP_EOL.PHP_EOL;
  145.     }
  146.     else
  147.         $_body .= '-'.PHP_EOL.PHP_EOL;
  148.     $_body .= 'Message'.': ';
  149.     if (isset($_POST['item5']))
  150.     {
  151.         $_body .= $_POST['item5'].PHP_EOL.PHP_EOL;
  152.     }
  153.     else
  154.         $_body .= '-'.PHP_EOL.PHP_EOL;
  155.     if ($_FILES['item6']['error']==0)
  156.         $mail->AddAttachment($_FILES['item6']['tmp_name'],$_FILES['item6']['name']); // attachment
  157.             $mail->AddAddress($config['toemail'],$config['toname']); // e-mail address of receiver
  158.             //$mail->AddAddress("another.mail@another.address.com");  // e-mail address of another receiver.....
  159.             $mail->FromName = $_name; // Sender's full name
  160.             $mail->From = $_email; // sender's e-mail address
  161.             $mail->Return = $_email; // if email will not be delivered, notice will return here
  162.             $mail->Subject = 'Message from my website: '.$_subject;
  163.             $mail->Body .= $_body;
  164.             $sent = $mail->Send();//via smtp or phpmail
  165.             if($sent)
  166.                 {echo '<br/><br/><b>Thank You!</b><br/>Your message was successfully sent!☺<br/>We\'ll get back to you as soon as possible.';}
  167.             else
  168.                 {echo '<br/><br/><b>Sorry</b><br/>We encountered an error, when sending your message ☹';}
  169.             echo '<br/><br/>';
  170.       }
  171.     if (isset($_POST["submitForm"]) && $_POST['url']!='')
  172.         { echo 'Spam was detected. Message was not send. (Honeypot Captcha)';}
  173.     $op='+-*ab';
  174.     $op=$op[(rand()%strlen($op))];
  175.     if ($op=='a' || $op=='b') { $n = 66+rand()%24; } else { $n1 = rand()%10; $n2 = rand()%10; }
  176.    
  177.     echo '
  178.         <div id="scf_jsContentWrapper" style="display:none;">
  179.  
  180. <div>Contact Form</div><br/>
  181. <form enctype="multipart/form-data" action="" method="post" name="special_contact_form" class="scf">
  182. <fieldset>
  183.  <label><b>Your name</b>
  184.   <input id="item1" name="item1" type="text" value="" />
  185.    *(required)
  186.    <span class="error_strings" id="special_contact_form_item1_errorloc"> </span>  </label>
  187.  <label><b>Your phone</b>
  188.   <input id="item2" name="item2" type="text" value="" />
  189.    *(recommended)
  190.    <span class="error_strings" id="special_contact_form_item2_errorloc"> </span>  </label>
  191.  <label><b>Your e-mail</b>
  192.   <input id="item3" name="item3" type="text" value="" />
  193.    *(required)
  194.    <span class="error_strings" id="special_contact_form_item3_errorloc"> </span>  </label>
  195.  <label><b>Subject</b>
  196.  <select name="item4">
  197.    <option value="Appointment">Appointment</option>
  198.    <option value="Acknowledgment">Acknowledgment</option>
  199.    <option value="Complaint">Complaint</option>
  200.   </select>
  201.    <span class="error_strings" id="special_contact_form_item4_errorloc"> </span>  </label>
  202.  <label><b>Message</b>
  203.   <textarea id="item5" name="item5" cols="50" rows="5" style="height:20em; width:98%; border:1px solid #ccc;"></textarea>
  204.    <span class="error_strings" id="special_contact_form_item5_errorloc"> </span>  </label>
  205.  <label><b>file attachment</b>
  206.    (The maximum size of an uploaded file: 128MB)
  207.   <input id="item6" name="item6" type="file" value="" style="margin-right:90px"/>
  208.    <span class="error_strings" id="special_contact_form_item6_errorloc"> </span>  </label>
  209.  <label for="check"><b>Antispam protection</b>
  210.    <span style="float:left">Please enter the result '; if ($op=='+') echo $n1.' + '.$n2; if ($op=='-') echo $n1+$n2.' - '.$n1; if ($op=='*') echo $n1.' * '.$n2; if ($op=='a') { $tempstring='the letter between %a and %c'; echo ' '.str_replace(array('%a','%c'),array(chr($n-1),chr($n+1)),$tempstring); }
  211. if ($op=='b') { echo 'unique letter in '; $rc=65+rand()%26; if($rc==$n) $rc=($n==65?90:65); $pos=1+rand()%5; for($rs=0;$rs<7;$rs++) echo ($rs==$pos)?chr($n):chr($rc); }
  212. echo ' : </span>
  213.    <input id="check" name="check" type="text" value="" class="scf_input" />
  214.  </label>
  215.    <input class="scf_submit" name="submitForm" type="submit" value="Send" />
  216.    <input id="url" name="url" type="text" value="" style="display:none" />
  217.    <input id="website" name="website" type="text" value="" style="display:none" />
  218.    <span class="error_strings" id="special_contact_form_check_errorloc"> </span>
  219. </fieldset>
  220. </form>
  221. </div>';
  222.  
  223. if (!isset($_POST["submitForm"]))
  224. { echo '<script type="text/javascript">$(\'#scf_jsContentWrapper\').removeAttr(\'style\'); </script>'.PHP_EOL; }
  225. echo '
  226.     <script type="text/javascript">
  227.         var frmvalidator  = new Validator("special_contact_form");
  228.         frmvalidator.EnableOnPageErrorDisplay();
  229.         frmvalidator.addValidation("item1","req","Please enter the required field - Your name");
  230.         frmvalidator.addValidation("item1","minlength=2","The entered value is too short for this field - Your name");
  231.         frmvalidator.addValidation("item1","maxlength=50","The entered value is too long for this field - Your name");
  232.         frmvalidator.addValidation("item2","maxlength=30","The entered value is too long for this field - Your phone");
  233.         frmvalidator.addValidation("item3","req","Please enter the required field - Your e-mail");
  234.         frmvalidator.addValidation("item3","email","Please enter your email address");
  235.         frmvalidator.addValidation("item4","req","Please enter the required field - Subject");
  236.         frmvalidator.addValidation("item4","minlength=2","The entered value is too short for this field - Subject");
  237.         frmvalidator.addValidation("item5","req","Please enter the required field - Message");
  238.         frmvalidator.addValidation("url","maxlen=0","This field must be empty. You must be a bot.");
  239.             frmvalidator.addValidation("check","req","Please check the antispam field and try again.");';
  240.         if ($op=='+') echo '
  241.             frmvalidator.addValidation("check","numeric","Please check the antispam field and try again.");
  242.             frmvalidator.addValidation("check","greaterthan='.($n1+$n2-1).'","Please check the antispam field and try again.");
  243.             frmvalidator.addValidation("check","lessthan='.($n1+$n2+1).'","Please check the antispam field and try again.");';
  244.         if ($op=='-') echo '
  245.             frmvalidator.addValidation("check","numeric","Please check the antispam field and try again.");
  246.             frmvalidator.addValidation("check","greaterthan='.($n2-1).'","Please check the antispam field and try again.");
  247.             frmvalidator.addValidation("check","lessthan='.($n2+1).'","Please check the antispam field and try again.");';
  248.          if ($op=='*') echo '
  249.             frmvalidator.addValidation("check","numeric","Please check the antispam field and try again.");
  250.             frmvalidator.addValidation("check","greaterthan='.($n1*$n2-1).'","Please check the antispam field and try again.");
  251.             frmvalidator.addValidation("check","lessthan='.($n1*$n2+1).'","Please check the antispam field and try again.");';
  252.          if ($op=='a' || $op=='b') echo '
  253.             frmvalidator.addValidation("check","alpha","Please check the antispam field and try again.");
  254.             frmvalidator.addValidation("check","regexp=['.chr($n).']|['.chr($n+32).']","Please check the antispam field and try again.");';
  255.        
  256. echo '  </script>
  257. </div>
  258. ';
Advertisement
RAW Paste Data Copied
Advertisement