ch_dropdown.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class ch_dropdown
  5. */
  6. class ch_dropdown extends survey_question
  7. {
  8. /**
  9. * @param array $survey_data
  10. * @param $formData
  11. * @return FormValidator
  12. */
  13. public function createForm($survey_data, $formData)
  14. {
  15. parent::createForm($survey_data, $formData);
  16. // The answers
  17. /*$this->html .= ' <div class="row">';
  18. $this->html .= ' <label class="control-label">';
  19. $this->html .= get_lang('AnswerOptions');
  20. $this->html .= ' </label>';
  21. $this->html .= ' <div class="formw">';
  22. $total_number_of_answers = count($form_content['answers']);
  23. $this->html .= ' <table>';
  24. foreach ($form_content['answers'] as $key => & $value) {
  25. $this->html .= ' <tr>';
  26. $this->html .= ' <td align="right"><label for="answers['.$key.']">'.($key + 1).'</label></td>';
  27. $this->html .= ' <td><input type="text" name="answers['.$key.']" id="answers['.$key.']" value="'.stripslashes($form_content['answers'][$key]).'" /></td>';
  28. $this->html .= ' <td>';
  29. if ($key < $total_number_of_answers - 1) {
  30. $this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/down.png" value="move_down['.$key.']" name="move_down['.$key.']"/>';
  31. }
  32. if ($key > 0) {
  33. $this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/up.png" value="move_up['.$key.']" name="move_up['.$key.']"/>';
  34. }
  35. if ($total_number_of_answers> 2) {
  36. $this->html .= ' <input type="image" style="width:22px" src="../img/icons/22/delete.png" value="delete_answer['.$key.']" name="delete_answer['.$key.']"/>';
  37. }
  38. $this->html .= ' </td>';
  39. $this->html .= ' </tr>';
  40. }
  41. // The buttons for adding or removing
  42. $this->html .= ' </table>';
  43. $this->html .= ' </div>';
  44. $this->html .= ' </div>';*/
  45. if (is_array($formData['answers'])) {
  46. foreach ($formData['answers'] as $key => $value) {
  47. $this->getForm()->addText('answers['.$key.']', $key + 1);
  48. }
  49. }
  50. parent :: addRemoveButtons($formData);
  51. }
  52. /**
  53. * @param FormValidator $form
  54. * @param array $questionData
  55. * @param array $answers
  56. */
  57. public function render(FormValidator $form, $questionData = array(), $answers = array())
  58. {
  59. $form->addSelect("question".$questionData['question_id'], null, $questionData['options']);
  60. }
  61. }