ch_dropdown.php 1.1 KB

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