Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter('widget_text', 'do_shortcode');
- /* Email Validation Function */
- function c_checkEmailAddress($email) {
- if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
- return false;
- }
- $email_array = explode("@", $email);
- $local_array = explode(".", $email_array[0]);
- for ($i = 0; $i < sizeof($local_array); $i++) {
- if
- (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
- '*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
- $local_array[$i])) {
- return false;
- }
- }
- if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
- $domain_array = explode(".", $email_array[1]);
- if (sizeof($domain_array) < 2) {
- return false; // Not enough parts to domain
- }
- for ($i = 0; $i < sizeof($domain_array); $i++) {
- if
- (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
- ([A-Za-z0-9]+))$",
- $domain_array[$i])) {
- return false;
- }
- }
- }
- return true;
- }
- function c_customContact(){
- /* Constants*/
- $html = null;
- $successMsg = null;
- $errorMsg = null;
- $to = 'mmashke@comcast.net'; // To Address
- $cc = null; //Enter CC Email Address
- $bcc = null; //Enter BCC Email Address
- $placeholder = array(
- 'c_name' => 'Name',
- 'c_phone' => 'Phone',
- 'c_email' => 'Email',
- 'c_1' => 'Property Address',
- 'c_2' => 'City',
- 'c_3' => 'Zip Code',
- 'c_comment' => 'Comment',
- ); // Placeholder
- $data = $placeholder;
- $required = array('c_email'); // Required Fields
- if(isset($_POST['c_submit']) && $_POST['c_submit']!=''){
- $data = array();
- unset($_POST['c_submit']);
- foreach($_POST as $field=>$fieldvalue){
- if (in_array($field, $required)) {
- if(isset($field) && $fieldvalue ==''){
- $errorMsg = 'Invalid '.$placeholder[$field].'!';
- }
- if($field == 'c_email'){
- if(!c_checkEmailAddress($fieldvalue)){
- $errorMsg = 'Invalid '.$placeholder[$field].'!';
- }
- }
- }
- //if($fieldvalue== $placeholder[$field])$fieldvalue = '';
- $data[$field] = $fieldvalue;
- }
- if(empty($errorMsg)){
- $message = null;
- foreach($data as $key=>$val){
- $message .= $placeholder[$key] . ' : ' . $val . '<br>';
- }
- $subject = 'Contact Form';
- $headers = 'Reply-To: '. $data['c_email'] . '\r\n';
- if($cc)
- $headers .= 'Cc: '.$cc . "\r\n";
- if($bcc)
- $headers .= 'Bcc: '.$bcc . "\r\n";
- add_filter('wp_mail_from',create_function('', 'return "'.get_bloginfo('admin_email').'";'));
- add_filter('wp_mail_from_name',create_function('', 'return "'.get_bloginfo('name').'";'));
- add_filter('wp_mail_content_type',create_function('', 'return "text/html";'));
- if(wp_mail( $to, $subject, $message, $headers)){
- $successMsg = 'Thank you for contact!';
- $data = $placeholder;
- }
- unset($_POST);
- }
- }
- $html .= '<div id="quickcontact">';
- $html .= '<form action="" name="c_form" method="post">';
- $html .= '<table width="100%" border="0">';
- if((isset($errorMsg) && $errorMsg!= null) || (isset($successMsg) && $successMsg!= null)){
- $html .= '<tr>';
- if($errorMsg!=null){
- $html .= '<td style="color:#FF0000;">'.$errorMsg.'</td>';
- }
- if($successMsg!=null){
- $html .= '<td style="color:#118d00;">'.$successMsg.'</td>';
- }
- $html .= '</tr>';
- }
- $html .= '<tr><td>';
- //Name Field
- $html .= '<input type="text" name="c_name" value="'.$data['c_name'].'"
- onfocus="if (this.value==\'Name\') { this.value = \'\'; }"
- onblur="if (this.value == \'\') { this.value = \'Name\'; }">';
- $html .= '</td></tr>';
- $html .= '<tr><td>';
- //Phone Field
- $html .= '<input type="text" name="c_phone" value="'.$data['c_phone'].'"
- onfocus="if (this.value==\'Phone\') { this.value = \'\'; }"
- onblur="if (this.value == \'\') { this.value = \'Phone\'; }">';
- $html .= '</td></tr>';
- $html .= '<tr><td>';
- //Email Field
- $html .= '<input type="text" name="c_email" value="'.$data['c_email'].'"
- onfocus="if (this.value==\'Email\') { this.value = \'\'; }"
- onblur="if (this.value == \'\') { this.value = \'Email\'; }">';
- $html .= '</td></tr>';
- $html .= '<tr><td>';
- //Property Address Field
- $html .= '<input type="text" name="c_1" value="'.$data['c_1'].'"
- onfocus="if (this.value==\'Property Address\') { this.value = \'\'; }"
- onblur="if (this.value == \'\') { this.value = \'Property Address\'; }">';
- $html .= '</td></tr>';
- $html .= '<tr><td>';
- //City Field
- $html .= '<input type="text" name="c_2" value="'.$data['c_2'].'"
- onfocus="if (this.value==\'City\') { this.value = \'\'; }"
- onblur="if (this.value == \'\') { this.value = \'City\'; }">';
- $html .= '</td></tr>';
- $html .= '<tr><td>';
- //Zip Code Field
- $html .= '<input type="text" name="c_3" value="'.$data['c_3'].'"
- onfocus="if (this.value==\'Zip Code\') { this.value = \'\'; }"
- onblur="if (this.value == \'\') { this.value = \'Zip Code\'; }">';
- $html .= '</td></tr>';
- $html .= '<tr><td>';
- //Comment Field
- $html .= '<textarea name="c_comment" onfocus="if (this.value==\'Comment\') { this.value = \'\'; }"
- onblur="if (this.value == \'\') { this.value = \'Comment\'; }">'.$data['c_comment'].'</textarea>';
- $html .= '</td></tr>';
- $html .= '<tr><td>';
- //Comment Field
- $html .= '<script type="text/javascript"
- src="http://www.google.com/recaptcha/api/challenge?k=6LcxFNwSAAAAAPJz5KpC65eyRUdXy8VwF8umQZH5">
- </script>
- <noscript>
- <iframe src="http://www.google.com/recaptcha/api/noscript?k=6LcxFNwSAAAAAPJz5KpC65eyRUdXy8VwF8umQZH5"
- height="300" width="500" frameborder="0"></iframe><br>
- <textarea name="recaptcha_challenge_field" rows="3" cols="40">
- </textarea>
- <input type="hidden" name="recaptcha_response_field"
- value="manual_challenge">
- </noscript>';
- $html .= '<input type="submit" name="c_submit" value="Send">';
- $html .= '</td></tr>';
- $html .= '</table>';
- $html .= '</form>';
- $html .= '</div>';
- return $html;
- }
- add_shortcode('C_Contact','c_customContact');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement