Advertisement
Guest User

Untitled

a guest
Jan 25th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. add_filter('widget_text', 'do_shortcode');
  5.  
  6. /* Email Validation Function */
  7.  
  8. function c_checkEmailAddress($email) {
  9.  
  10. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
  11.  
  12. return false;
  13.  
  14. }
  15.  
  16.  
  17.  
  18. $email_array = explode("@", $email);
  19.  
  20. $local_array = explode(".", $email_array[0]);
  21.  
  22. for ($i = 0; $i < sizeof($local_array); $i++) {
  23.  
  24. if
  25.  
  26. (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
  27.  
  28. '*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
  29.  
  30. $local_array[$i])) {
  31.  
  32. return false;
  33.  
  34. }
  35.  
  36. }
  37.  
  38.  
  39.  
  40. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
  41.  
  42. $domain_array = explode(".", $email_array[1]);
  43.  
  44. if (sizeof($domain_array) < 2) {
  45.  
  46. return false; // Not enough parts to domain
  47.  
  48. }
  49.  
  50. for ($i = 0; $i < sizeof($domain_array); $i++) {
  51.  
  52. if
  53.  
  54. (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
  55.  
  56. ([A-Za-z0-9]+))$",
  57.  
  58. $domain_array[$i])) {
  59.  
  60. return false;
  61.  
  62. }
  63.  
  64. }
  65.  
  66. }
  67.  
  68. return true;
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. function c_customContact(){
  81.  
  82.  
  83.  
  84. /* Constants*/
  85.  
  86. $html = null;
  87.  
  88. $successMsg = null;
  89.  
  90. $errorMsg = null;
  91.  
  92.  
  93.  
  94. $to = 'mmashke@comcast.net'; // To Address
  95.  
  96. $cc = null; //Enter CC Email Address
  97.  
  98. $bcc = null; //Enter BCC Email Address
  99.  
  100.  
  101.  
  102. $placeholder = array(
  103.  
  104. 'c_name' => 'Name',
  105.  
  106. 'c_phone' => 'Phone',
  107.  
  108. 'c_email' => 'Email',
  109.  
  110. 'c_1' => 'Property Address',
  111.  
  112. 'c_2' => 'City',
  113.  
  114. 'c_3' => 'Zip Code',
  115.  
  116. 'c_comment' => 'Comment',
  117.  
  118. ); // Placeholder
  119.  
  120. $data = $placeholder;
  121.  
  122. $required = array('c_email'); // Required Fields
  123.  
  124.  
  125.  
  126. if(isset($_POST['c_submit']) && $_POST['c_submit']!=''){
  127.  
  128.  
  129.  
  130. $data = array();
  131.  
  132. unset($_POST['c_submit']);
  133.  
  134. foreach($_POST as $field=>$fieldvalue){
  135.  
  136. if (in_array($field, $required)) {
  137.  
  138. if(isset($field) && $fieldvalue ==''){
  139.  
  140. $errorMsg = 'Invalid '.$placeholder[$field].'!';
  141.  
  142. }
  143.  
  144.  
  145.  
  146. if($field == 'c_email'){
  147.  
  148. if(!c_checkEmailAddress($fieldvalue)){
  149.  
  150. $errorMsg = 'Invalid '.$placeholder[$field].'!';
  151.  
  152. }
  153.  
  154. }
  155.  
  156. }
  157.  
  158.  
  159.  
  160. //if($fieldvalue== $placeholder[$field])$fieldvalue = '';
  161.  
  162. $data[$field] = $fieldvalue;
  163.  
  164. }
  165.  
  166.  
  167.  
  168. if(empty($errorMsg)){
  169.  
  170. $message = null;
  171.  
  172. foreach($data as $key=>$val){
  173.  
  174. $message .= $placeholder[$key] . ' : ' . $val . '<br>';
  175.  
  176. }
  177.  
  178.  
  179.  
  180.  
  181.  
  182. $subject = 'Contact Form';
  183.  
  184. $headers = 'Reply-To: '. $data['c_email'] . '\r\n';
  185.  
  186.  
  187.  
  188. if($cc)
  189.  
  190. $headers .= 'Cc: '.$cc . "\r\n";
  191.  
  192. if($bcc)
  193.  
  194. $headers .= 'Bcc: '.$bcc . "\r\n";
  195.  
  196.  
  197.  
  198. add_filter('wp_mail_from',create_function('', 'return "'.get_bloginfo('admin_email').'";'));
  199.  
  200. add_filter('wp_mail_from_name',create_function('', 'return "'.get_bloginfo('name').'";'));
  201.  
  202. add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
  203.  
  204. if(wp_mail( $to, $subject, $message, $headers)){
  205.  
  206. $successMsg = 'Thank you for contact!';
  207.  
  208. $data = $placeholder;
  209.  
  210. }
  211.  
  212.  
  213.  
  214. unset($_POST);
  215.  
  216. }
  217.  
  218.  
  219.  
  220. }
  221.  
  222.  
  223.  
  224.  
  225.  
  226. $html .= '<div id="quickcontact">';
  227.  
  228. $html .= '<form action="" name="c_form" method="post">';
  229.  
  230. $html .= '<table width="100%" border="0">';
  231.  
  232. if((isset($errorMsg) && $errorMsg!= null) || (isset($successMsg) && $successMsg!= null)){
  233.  
  234. $html .= '<tr>';
  235.  
  236.  
  237.  
  238. if($errorMsg!=null){
  239.  
  240. $html .= '<td style="color:#FF0000;">'.$errorMsg.'</td>';
  241.  
  242. }
  243.  
  244.  
  245.  
  246. if($successMsg!=null){
  247.  
  248. $html .= '<td style="color:#118d00;">'.$successMsg.'</td>';
  249.  
  250. }
  251.  
  252.  
  253.  
  254. $html .= '</tr>';
  255.  
  256. }
  257.  
  258.  
  259.  
  260. $html .= '<tr><td>';
  261.  
  262.  
  263.  
  264.  
  265.  
  266. //Name Field
  267.  
  268. $html .= '<input type="text" name="c_name" value="'.$data['c_name'].'"
  269.  
  270. onfocus="if (this.value==\'Name\') { this.value = \'\'; }"
  271.  
  272. onblur="if (this.value == \'\') { this.value = \'Name\'; }">';
  273.  
  274.  
  275.  
  276. $html .= '</td></tr>';
  277.  
  278. $html .= '<tr><td>';
  279.  
  280.  
  281.  
  282. //Phone Field
  283.  
  284. $html .= '<input type="text" name="c_phone" value="'.$data['c_phone'].'"
  285.  
  286. onfocus="if (this.value==\'Phone\') { this.value = \'\'; }"
  287.  
  288. onblur="if (this.value == \'\') { this.value = \'Phone\'; }">';
  289.  
  290.  
  291.  
  292. $html .= '</td></tr>';
  293.  
  294. $html .= '<tr><td>';
  295.  
  296.  
  297.  
  298. //Email Field
  299.  
  300. $html .= '<input type="text" name="c_email" value="'.$data['c_email'].'"
  301.  
  302. onfocus="if (this.value==\'Email\') { this.value = \'\'; }"
  303.  
  304. onblur="if (this.value == \'\') { this.value = \'Email\'; }">';
  305.  
  306.  
  307.  
  308. $html .= '</td></tr>';
  309.  
  310. $html .= '<tr><td>';
  311.  
  312.  
  313.  
  314. //Property Address Field
  315.  
  316. $html .= '<input type="text" name="c_1" value="'.$data['c_1'].'"
  317.  
  318. onfocus="if (this.value==\'Property Address\') { this.value = \'\'; }"
  319.  
  320. onblur="if (this.value == \'\') { this.value = \'Property Address\'; }">';
  321.  
  322.  
  323.  
  324. $html .= '</td></tr>';
  325.  
  326. $html .= '<tr><td>';
  327.  
  328.  
  329. //City Field
  330.  
  331. $html .= '<input type="text" name="c_2" value="'.$data['c_2'].'"
  332.  
  333. onfocus="if (this.value==\'City\') { this.value = \'\'; }"
  334.  
  335. onblur="if (this.value == \'\') { this.value = \'City\'; }">';
  336.  
  337.  
  338.  
  339. $html .= '</td></tr>';
  340.  
  341. $html .= '<tr><td>';
  342.  
  343. //Zip Code Field
  344.  
  345. $html .= '<input type="text" name="c_3" value="'.$data['c_3'].'"
  346.  
  347. onfocus="if (this.value==\'Zip Code\') { this.value = \'\'; }"
  348.  
  349. onblur="if (this.value == \'\') { this.value = \'Zip Code\'; }">';
  350.  
  351.  
  352.  
  353. $html .= '</td></tr>';
  354.  
  355. $html .= '<tr><td>';
  356.  
  357. //Comment Field
  358.  
  359. $html .= '<textarea name="c_comment" onfocus="if (this.value==\'Comment\') { this.value = \'\'; }"
  360.  
  361. onblur="if (this.value == \'\') { this.value = \'Comment\'; }">'.$data['c_comment'].'</textarea>';
  362.  
  363.  
  364.  
  365. $html .= '</td></tr>';
  366.  
  367. $html .= '<tr><td>';
  368.  
  369.  
  370.  
  371. //Comment Field
  372. $html .= '<script type="text/javascript"
  373. src="http://www.google.com/recaptcha/api/challenge?k=6LcxFNwSAAAAAPJz5KpC65eyRUdXy8VwF8umQZH5">
  374. </script>
  375. <noscript>
  376. <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LcxFNwSAAAAAPJz5KpC65eyRUdXy8VwF8umQZH5"
  377. height="300" width="500" frameborder="0"></iframe><br>
  378. <textarea name="recaptcha_challenge_field" rows="3" cols="40">
  379. </textarea>
  380. <input type="hidden" name="recaptcha_response_field"
  381. value="manual_challenge">
  382. </noscript>';
  383.  
  384. $html .= '<input type="submit" name="c_submit" value="Send">';
  385.  
  386.  
  387.  
  388. $html .= '</td></tr>';
  389.  
  390.  
  391.  
  392. $html .= '</table>';
  393.  
  394. $html .= '</form>';
  395.  
  396. $html .= '</div>';
  397.  
  398.  
  399.  
  400. return $html;
  401.  
  402.  
  403.  
  404. }
  405.  
  406.  
  407.  
  408. add_shortcode('C_Contact','c_customContact');
  409.  
  410. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement