ch_dropdown.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. if (is_array($formData['answers'])) {
  17. foreach ($formData['answers'] as $key => $value) {
  18. $this->getForm()->addText('answers['.$key.']', $key + 1);
  19. }
  20. }
  21. parent :: addRemoveButtons($formData);
  22. }
  23. /**
  24. * @param FormValidator $form
  25. * @param array $questionData
  26. * @param array $answers
  27. */
  28. public function render(FormValidator $form, $questionData = array(), $answers = '')
  29. {
  30. $name = 'question' . $questionData['question_id'];
  31. $form->addSelect($name, null, $questionData['options']);
  32. if (!empty($answers)) {
  33. $form->setDefaults([$name => $answers]);
  34. }
  35. }
  36. }