'arixwp_contact_form', 'description' => __( 'Display a contact form in your sidebar.', THEMENAME ) ); parent::WP_Widget(false,$name= "arixWP Contact Form",$widgets_opt); } // User Options Form function form($instance) { $this->arixwp_contact_title = ( !empty( $instance['title'] ) ) ? esc_attr( $instance['title'] ) : ''; $this->arixwp_mailto = ( !empty( $instance['arixwp_mailto'] ) ) ? esc_attr( $instance['arixwp_mailto'] ) : ''; $this->arixwp_mailto_dept = ( !empty( $instance['arixwp_mailto_dept'] ) ) ? esc_attr( $instance['arixwp_mailto_dept'] ) : ''; $this->arixwp_mail_subject = ( !empty( $instance['arixwp_mail_subject'] ) ) ? esc_attr( $instance['arixwp_mail_subject'] ) : ''; ?>

arixwp_contact_title = ( !empty( $instance['title'] ) ) ? apply_filters( 'title',$instance['title'] ) : __(ARIXWP_CONTACT_WIDGET_TITLE, THEMENAME); $this->arixwp_mailto = ( !empty( $instance['arixwp_mailto'] ) ) ? apply_filters( 'arixwp_mailto',$instance['arixwp_mailto'] ) : ''; $this->arixwp_mailto_dept = ( !empty( $instance['arixwp_mailto_dept'] ) ) ? apply_filters( 'arixwp_mailto_dept',$instance['arixwp_mailto_dept'] ) : ''; $this->arixwp_mail_subject = ( !empty( $instance['arixwp_mail_subject'] ) ) ? apply_filters( 'arixwp_mail_subject',$instance['arixwp_mail_subject'] ) : ''; echo $before_widget; $arixwp_contact_title2 = preg_replace('/(^[A-z0-9_]+)\s/i', '$1 ', $this->arixwp_contact_title); $title = $before_title.$arixwp_contact_title2.$after_title; echo $title; $this->doWidgetLogic($args); wp_reset_query(); echo $after_widget; } function doWidgetLogic($args) { extract($args); $arixwp_mailto = $this->arixwp_mailto; $arixwp_mailto_dept = $this->arixwp_mailto_dept; $arixwp_mail_subject = $this->arixwp_mail_subject; $widget_id = ( !empty( $widget_id ) ) ? $widget_id : ''; if ($arixwp_mailto == "") { _e('You must assign an Mail To: address in the Widget options to use the Contact Form.', THEMENAME); $passedAll = false; } else { $passedAll = true; } if ($passedAll) { $form_instance = "_" . $widget_id; $name_error = ""; $deptError = ""; $emailError = ""; $subjectError = ""; $commentError = ""; // See if form was submitted if ( isset( $_POST['arixwp_mail'.$form_instance] ) ) { // Validate URL (spambot) $url = filter_input( INPUT_POST, 'url', FILTER_SANITIZE_STRING ); if ( !isset($url) ) { } else { $emailSent = true; } // Validate Department $dept_email = filter_input(INPUT_POST, 'dept_name'.$form_instance, FILTER_SANITIZE_STRING); // Validate Name $contact_name = filter_input(INPUT_POST, 'contact_name'.$form_instance, FILTER_SANITIZE_STRING); if ( $contact_name == '' ) { $name_error = __('Please enter a valid name.', THEMENAME); $has_error = true; } // Validate Email $email = filter_input( INPUT_POST, 'email'.$form_instance, FILTER_SANITIZE_EMAIL ); if ( !filter_var( $email, FILTER_VALIDATE_EMAIL ) ) { $emailError = $email . ' ' . __('is NOT a valid email address.', THEMENAME); $has_error = true; } // Validate Subject $subject = filter_input( INPUT_POST, 'subject'.$form_instance, FILTER_SANITIZE_STRING ); if ( $subject == '' ) { $subjectError = __('Please enter a valid subject.', THEMENAME); $has_error = true; } // Validate Message $message = filter_input( INPUT_POST, 'message'.$form_instance, FILTER_SANITIZE_STRING); if ( $message == '' ) { $commentError = __('Please enter a message to send.', THEMENAME) . '
'; $has_error = true; } // If we didn't hit an error, send the email if ( !isset( $has_error ) ) { // Body: $body = ' Name: ' . $contact_name . ' Email: ' . $email . ' Comments: ' . $message . ' '; // Headers $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n"; // Send it if ( $dept_email != "" ) { mail( $dept_email, $arixwp_mail_subject . ' : ' . $subject , $body, $headers ); } else { $arixwp_mailto = explode( ',',$arixwp_mailto ); mail( $arixwp_mailto[0], $arixwp_mail_subject . ' : ' . $subject , $body, $headers ); } $emailSent = true; } else { ?> ' . __( 'Thanks', THEMENAME ) . ', ' . $contact_name . '

' . __( 'Your email was successfully sent. I will be in touch soon.', THEMENAME ) . '

'; ?>