private function validate()
 {
     $this->errors = array();
     if (!isset($_REQUEST['listing_id'])) {
         die;
     }
     // Verify nonce.
     if (!isset($_POST['_wpnonce']) || !isset($_POST['_wp_http_referer']) || !wp_verify_nonce($_POST['_wpnonce'], 'contact-form-' . $_REQUEST['listing_id'])) {
         die;
     }
     if (!$this->name) {
         $this->errors[] = _x('Please enter your name.', 'contact-message', 'WPBDM');
     }
     if (!wpbdp_validate_value($this->email, 'email')) {
         $this->errors[] = _x("Please enter a valid email.", 'contact-message', "WPBDM");
     }
     if (!$this->message) {
         $this->errors[] = _x('You did not enter a message.', 'contact-message', 'WPBDM');
     }
     if (wpbdp_get_option('recaptcha-on') && !wpbdp_recaptcha_check_answer()) {
         $this->errors[] = _x("The reCAPTCHA wasn't entered correctly.", 'contact-message', 'WPBDM');
     }
     return empty($this->errors);
 }
 protected function step_listing_fields()
 {
     $fields = wpbdp_get_form_fields(array('association' => '-category'));
     $fields = apply_filters_ref_array('wpbdp_listing_submit_fields', array(&$fields, &$this->state));
     $validation_errors = array();
     if (isset($_POST['listingfields']) && isset($_POST['step']) && 'listing_fields' == $_POST['step']) {
         $_POST['listingfields'] = stripslashes_deep($_POST['listingfields']);
         foreach ($fields as &$f) {
             $value = $f->convert_input(wpbdp_getv($_POST['listingfields'], $f->get_id(), null));
             $this->state->fields[$f->get_id()] = $value;
             $field_errors = null;
             $validate_res = apply_filters_ref_array('wpbdp_listing_submit_validate_field', array($f->validate($value, $field_errors), &$field_errors, &$f, $value, &$this->state));
             if (!$validate_res) {
                 $validation_errors = array_merge($validation_errors, $field_errors);
             }
         }
         if (!$this->state->editing && !current_user_can('administrator') && wpbdp_get_option('display-terms-and-conditions')) {
             $tos = trim(wpbdp_get_option('terms-and-conditions'));
             if ($tos && (!isset($_POST['terms-and-conditions-agreement']) || $_POST['terms-and-conditions-agreement'] != 1)) {
                 $validation_errors[] = _x('Please agree to the Terms and Conditions.', 'templates', 'WPBDM');
             }
         }
         if (wpbdp_get_option('recaptcha-for-submits')) {
             if (!wpbdp_recaptcha_check_answer()) {
                 $validation_errors[] = _x("The reCAPTCHA wasn't entered correctly.", 'templates', 'WPBDM');
             }
         }
         if (!$validation_errors) {
             $this->state->advance();
             return $this->dispatch();
         }
     }
     $terms_field = '';
     if (!$this->state->editing && wpbdp_get_option('display-terms-and-conditions')) {
         $tos = trim(wpbdp_get_option('terms-and-conditions'));
         if ($tos) {
             if (wpbdp_starts_with($tos, 'http://', false) || wpbdp_starts_with($tos, 'https://', false)) {
                 $terms_field .= sprintf('<a href="%s" target="_blank">%s</a>', esc_url($tos), _x('Read our Terms and Conditions', 'templates', 'WPBDM'));
             } else {
                 $terms_field .= '<div class="wpbdp-form-field-label">';
                 $terms_field .= '<label>';
                 $terms_field .= _x('Terms and Conditions:', 'templates', 'WPBDM');
                 $terms_field .= '</label>';
                 $terms_field .= '</div>';
                 $terms_field .= '<div class="wpbdp-form-field-html wpbdp-form-field-inner">';
                 $terms_field .= sprintf('<textarea readonly="readonly" rows="5" cols="50">%s</textarea>', esc_textarea($tos));
                 $terms_field .= '</div>';
             }
             $terms_field .= '<label>';
             $terms_field .= '<input type="checkbox" name="terms-and-conditions-agreement" value="1" />';
             $terms_field .= _x('I agree to the Terms and Conditions', 'templates', 'WPBDM');
             $terms_field .= '</label>';
         }
     }
     $recaptcha = '';
     if (wpbdp_get_option('recaptcha-for-submits')) {
         $recaptcha = wpbdp_recaptcha();
     }
     return $this->render('listing-fields', array('fields' => $fields, 'validation_errors' => $validation_errors, 'recaptcha' => $recaptcha, 'terms_and_conditions' => $terms_field));
 }