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)); }
public function render_form($listing_id = 0, $validation_errors = array()) { if (!$listing_id || !apply_filters('wpbdp_show_contact_form', wpbdp_get_option('show-contact-form'), $listing_id)) { return ''; } $html = ''; $html .= '<div class="contact-form">'; if (!$_POST) { $html .= '<input type="button" class="wpbdp-show-on-mobile send-message-button" value="' . _x('Contact listing owner', 'templates', 'WPBDM') . '" />'; $html .= '<div class="wpbdp-hide-on-mobile contact-form-wrapper">'; } $html .= '<h3>' . _x('Send Message to listing owner', 'templates', 'WPBDM') . '</h3>'; $form = ''; if (!$this->can_submit($listing_id, $error_msg)) { $form = wpbdp_render_msg($error_msg); } else { $form = wpbdp_render('listing-contactform', array('validation_errors' => $validation_errors, 'listing_id' => $listing_id, 'current_user' => is_user_logged_in() ? wp_get_current_user() : null, 'recaptcha' => wpbdp_get_option('recaptcha-on') ? wpbdp_recaptcha('wpbdp-contact-form-recaptcha') : '', false)); } $html .= $form; if (!$_POST) { $html .= '</div>'; } $html .= '</div>'; return $html; }