コード例 #1
0
ファイル: form-process.php プロジェクト: arkonisus/Questions
 /**
  * Survey form
  *
  * Creating form HTML
  *
  * @param int $form_id
  * @return string $html
  * @since 1.0.0
  */
 private function survey_form($form_id)
 {
     global $questions_response_errors, $questions_survey_id;
     $questions_survey_id = $form_id;
     $form = new Questions_Form($form_id);
     do_action('before_survey_form');
     if (array_key_exists('questions_next_step', $_POST) && 0 == count($questions_response_errors)) {
         $next_step = (int) $_POST['questions_next_step'];
     } else {
         if (array_key_exists('questions_actual_step', $_POST)) {
             $next_step = (int) $_POST['questions_actual_step'];
         } else {
             $next_step = 0;
         }
     }
     if (array_key_exists('questions_submission_back', $_POST)) {
         $next_step = (int) $_POST['questions_actual_step'] - 1;
     }
     $actual_step = $next_step;
     $html = '<form name="questions" id="questions" action="' . $_SERVER['REQUEST_URI'] . '" method="POST">';
     $html .= '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce('questions-' . $form_id) . '" />';
     $step_count = $form->get_step_count();
     if (0 != $step_count) {
         $html .= '<div class="questions-pagination">' . sprintf(__('Step <span class="questions-highlight-number">%d</span> of <span class="questions-highlight-number">%s</span>', 'questions-locale'), $actual_step + 1, $step_count + 1) . '</div>';
     }
     $elements = $this->get_elements($form_id, $actual_step);
     if (is_array($elements) && count($elements) > 0) {
         foreach ($elements as $element) {
             if (!$element->splits_form) {
                 $html .= $element->draw();
             } else {
                 $next_step += 1;
                 break;
             }
         }
     } else {
         return FALSE;
     }
     if (0 < $actual_step) {
         $html .= '<input type="submit" name="questions_submission_back" value="' . __('Previous Step', 'questions-locale') . '"> ';
     }
     if ($actual_step == $next_step) {
         $html .= '<input type="submit" name="questions_submission" value="' . __('Finish Survey', 'questions-locale') . '">';
     } else {
         $html .= '<input type="submit" name="questions_submission" value="' . __('Next Step', 'questions-locale') . '">';
     }
     $html .= '<input type="hidden" name="questions_next_step" value="' . $next_step . '" />';
     $html .= '<input type="hidden" name="questions_actual_step" value="' . $actual_step . '" />';
     $html .= '<input type="hidden" name="questions_id" value="' . $form_id . '" />';
     $html .= '</form>';
     return $html;
 }