AddShowWhat.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. class Application_Form_AddShowWhat extends Zend_Form_SubForm
  3. {
  4. public function init()
  5. {
  6. $notEmptyValidator = Application_Form_Helper_ValidationTypes::overrideNotEmptyValidator();
  7. // retrieves the length limit for each char field
  8. // and store to assoc array
  9. $maxLens = Application_Model_Show::getMaxLengths();
  10. // Hidden element to indicate whether the show is new or
  11. // whether we are updating an existing show.
  12. $this->addElement('hidden', 'add_show_id', array(
  13. 'decorators' => array('ViewHelper')
  14. ));
  15. // Hidden element to indicate the instance id of the show
  16. // being edited.
  17. $this->addElement('hidden', 'add_show_instance_id', array(
  18. 'decorators' => array('ViewHelper')
  19. ));
  20. // Add name element
  21. $this->addElement('text', 'add_show_name', array(
  22. 'label' => _('Name:'),
  23. 'class' => 'input_text',
  24. 'required' => true,
  25. 'filters' => array('StringTrim'),
  26. 'value' => _('Untitled Show'),
  27. 'validators' => array($notEmptyValidator, array('StringLength', false, array(0, $maxLens['name'])))
  28. ));
  29. // Add URL element
  30. $this->addElement('text', 'add_show_url', array(
  31. 'label' => _('URL:'),
  32. 'class' => 'input_text',
  33. 'required' => false,
  34. 'filters' => array('StringTrim'),
  35. 'validators' => array($notEmptyValidator, array('StringLength', false, array(0, $maxLens['url'])))
  36. ));
  37. // Add genre element
  38. $this->addElement('text', 'add_show_genre', array(
  39. 'label' => _('Genre:'),
  40. 'class' => 'input_text',
  41. 'required' => false,
  42. 'filters' => array('StringTrim'),
  43. 'validators' => array(array('StringLength', false, array(0, $maxLens['genre'])))
  44. ));
  45. // Add the description element
  46. $this->addElement('textarea', 'add_show_description', array(
  47. 'label' => _('Description:'),
  48. 'required' => false,
  49. 'class' => 'input_text_area',
  50. 'validators' => array(array('StringLength', false, array(0, $maxLens['description'])))
  51. ));
  52. $descText = $this->getElement('add_show_description');
  53. $descText->setDecorators(array(array('ViewScript', array(
  54. 'viewScript' => 'form/add-show-block.phtml',
  55. 'class' => 'block-display'
  56. ))));
  57. }
  58. public function disable()
  59. {
  60. $elements = $this->getElements();
  61. foreach ($elements as $element) {
  62. if ($element->getType() != 'Zend_Form_Element_Hidden') {
  63. $element->setAttrib('disabled','disabled');
  64. }
  65. }
  66. }
  67. public function makeReadonly()
  68. {
  69. $elements = $this->getElements();
  70. foreach ($elements as $element) {
  71. if ($element->getType() != 'Zend_Form_Element_Hidden') {
  72. $element->setAttrib('readonly','readonly');
  73. }
  74. }
  75. }
  76. }