/**
  * Primary function to render a form on the frontend.
  *
  * @since 1.0.0
  * @param int $id
  * @param boolean $title
  * @param boolean $description
  */
 public function output($id, $title = false, $description = false)
 {
     // Grab the form data, if not found then we bail
     $form = wpforms()->form->get((int) $id);
     if (!$form) {
         return;
     }
     // Basic information
     $form_data = wpforms_decode($form->post_content, true);
     $form_id = absint($form->ID);
     $settings = $form_data['settings'];
     $action = esc_url_raw(remove_query_arg('wpforms'));
     $class[] = wpforms_setting('disable-css', '1') == '1' ? 'wpforms-container-full' : '';
     $errors = empty(wpforms()->process->errors[$form->ID]) ? array() : wpforms()->process->errors[$form->ID];
     $success = false;
     // If the form does not contain any fields do not proceed
     if (empty($form_data['fields'])) {
         echo '<!-- WPForms: no fields, form hidden -->';
         return;
     }
     // Before output hook
     do_action('wpforms_frontend_output_before', $form_data, $form);
     // Check for return hash OR error free completed form and confirmation before we continue
     if (!empty($_GET['wpforms_return'])) {
         $success = wpforms()->process->validate_return_hash($_GET['wpforms_return']);
         if ($success) {
             $form_data = wpforms()->form->get($success, array('content_only' => true));
         }
     } elseif (!empty($_POST['wpforms']['id']) && $form->ID == $_POST['wpforms']['id'] && empty($errors)) {
         $success = true;
     }
     if ($success && !empty($form_data)) {
         do_action('wpforms_frontend_output_success', $form_data);
         // Debug
         wpforms_debug_data($_POST);
         return;
     }
     // Allow filter to return early if some condition is not met.
     if (!apply_filters('wpforms_frontend_load', true, $form_data, $form)) {
         return;
     }
     // Prep the form action URL, allow filter
     if (!empty($settings['confirmation_type']) && 'message' == $settings['confirmation_type'] && !empty($settings['confirmation_message_scroll'])) {
         $action .= '#wpforms-' . $form_id;
     }
     $action = apply_filters('wpforms_frontend_form_action', $action, $form_data, $form);
     // Allow form container classes to be filtered
     $class = array_map('sanitize_html_class', apply_filters('wpforms_frontend_container_class', $class, $form_data));
     if (!empty($form_data['settings']['form_class'])) {
         $class = array_merge($class, array_map('sanitize_html_class', explode(' ', $form_data['settings']['form_class'])));
     }
     // Begin to build the output
     echo '<div class="wpforms-container ' . implode(' ', $class) . '" id="wpforms-' . $form_id . '">';
     echo '<form method="post" enctype="multipart/form-data" id="wpforms-form-' . $form_id . '" action="' . $action . '" class="wpforms-validate wpforms-form" data-formid="' . $form_id . '">';
     do_action('wpforms_frontend_output', $form_data, $form, $title, $description, $errors);
     echo '</form>';
     echo '</div>';
     // After output hook
     do_action('wpforms_frontend_output_after', $form_data, $form);
     $this->forms[$form_id] = $form_data;
     // Debug
     wpforms_debug_data($form_data);
 }
Ejemplo n.º 2
0
    /**
     * Outputs the Field panel primary content.
     *
     * @since 1.0.0
     */
    public function panel_content()
    {
        // Check if there is a form created
        if (!$this->form) {
            echo '<div class="wpforms-alert wpforms-alert-info">';
            _e('You need to <a href="#" class="wpforms-panel-switch" data-panel="setup">setup your form</a> before you can manage the fields.', 'wpforms');
            echo '</div>';
            return;
        }
        ?>
		<div class="wpforms-preview-wrap">

			<div class="wpforms-preview">

				<div class="wpforms-title-desc">
					<h2 class="wpforms-form-name"><?php 
        echo esc_html($this->form->post_title);
        ?>
</h2>
					<span class="wpforms-form-desc"><?php 
        echo $this->form->post_excerpt;
        ?>
</span>
				</div>

				<div class="wpforms-field-wrap">
					<?php 
        do_action('wpforms_builder_preview', $this->form);
        ?>
				</div>

				<p class="wpforms-field-recaptcha">
					<img src="<?php 
        echo WPFORMS_PLUGIN_URL;
        ?>
/assets/images/recaptcha-placeholder.png">
				</p>

				<?php 
        $submit = !empty($this->form_data['settings']['submit_text']) ? esc_attr($this->form_data['settings']['submit_text']) : __('Submit', 'wpforms');
        printf('<p class="wpforms-field-submit"><input type="submit" value="%s" class="wpforms-field-submit-button"></p>', $submit);
        ?>

				<?php 
        wpforms_debug_data($this->form_data);
        ?>
			</div>

		</div>
		<?php 
    }