Guest User

Untitled

a guest
Jan 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. <?php
  2.  
  3. class Application_Form_Custom extends Zend_Form
  4. {
  5. public function __construct($options = null) {
  6. parent::__construct($options);
  7.  
  8. $this->addElementPrefixPath('Shayan_Decorators',
  9. 'Shayan/Decorators/',
  10. 'decorator');
  11. $smallField = new Zend_Form_Element_Text("smallField");
  12. $smallField->setLabel("small field")
  13. ->setRequired(true)
  14. ->setValue("Small input field")
  15. ->setDescription("Field Description")
  16. ->setAttrib("class", "sf")
  17. ->setDecorators(array("Element",
  18. array(
  19. // Decorator name
  20. 'Callback',
  21. // Options
  22. array(
  23. 'callback' => array($this,"callback"),
  24. 'placement' => 'prepend',
  25. )
  26. ),
  27. ));
  28.  
  29. $mediumField = new Zend_Form_Element_Text("mediumField");
  30. $mediumField->setLabel("Medium field")
  31. ->setRequired(true)
  32. ->setValue("medium input field")
  33. ->setDescription("A positive message!")
  34. ->setAttrib("class", "mf")
  35. ->setDecorators(array("Element"));
  36.  
  37. $largeField = new Zend_Form_Element_Text("largeField");
  38. $largeField->setLabel("Large field")
  39. ->setRequired(true)
  40. ->setValue("large input field")
  41. ->setDescription("A negative message!")
  42. ->setAttrib("class", "lf")
  43. ->setDecorators(array("Element"));
  44.  
  45. $dateOfRegistration = new ZendX_JQuery_Form_Element_DatePicker(
  46. 'dateOfRegistration',
  47. array('jQueryParams' => array('dateFormat' => 'yy-mm-dd')));
  48. $dateOfRegistration->setLabel('Date Picker')
  49. ->addFilter('StripTags')
  50. ->addFilter('StringTrim')
  51. ->addValidator('Date')
  52. ->setDecorators(array(
  53. array('UiWidgetElement', array('tag' => '')),
  54. "Label",
  55. array("HtmlTag",array("tag"=>"<p>"))
  56. ));
  57.  
  58.  
  59. $dropDown = new Zend_Form_Element_Select("dropDown");
  60. $dropDown->setLabel("DropDown")
  61. ->addMultiOption("0","Select an option")
  62. ->addMultiOption("1","Upload")
  63. ->addMultiOption("2","Change")
  64. ->addMultiOption("3","Remove")
  65. ->setAttrib("class","dropdown")
  66. ->setDecorators(array("Element",
  67. array(array('HR' => 'HtmlTag'), array('tag' => '<hr>', 'placement' => 'append'))
  68. ));
  69.  
  70.  
  71. $checkbox = new Zend_Form_Element_MultiCheckbox("checkBox");
  72. $checkbox->setLabel("Normal Radio / Checkboxes")
  73. ->addMultiOption("0","Lorem Ipsum")
  74. ->addMultiOption("1","Lorem Ipsum")
  75. ->addMultiOption("2","Lorem Ipsum")
  76. ->addMultiOption("3","Lorem Ipsum")
  77. ->setDecorators(array(
  78. array("viewScript",
  79. array(
  80. "viewScript"=>"_multicheckbox.phtml",
  81. 'class'=> "one_fourth",
  82. "prefix"=>"<div class='one_half'><h2>Normal Radio / Checkboxes</h2></div>
  83. <div class='one_half_last'><h2>Iphone Checkboxes</h2></div>
  84. <div class='clearboth'></div>",
  85. ))));
  86. $radioButton = new Zend_Form_Element_Radio("radio");
  87. $radioButton->addMultiOption("0","Lorem Ipsum")
  88. ->addMultiOption("1","Lorem Ipsum")
  89. ->addMultiOption("2","Lorem Ipsum")
  90. ->addMultiOption("3","Lorem Ipsum")
  91. ->setDecorators(array(
  92. array("viewScript",
  93. array(
  94. "viewScript"=>"_multicheckbox.phtml",
  95. 'class'=> "one_fourth"
  96. ))));
  97.  
  98. $iphoneCheckbox = new Zend_Form_Element_MultiCheckbox("iphone");
  99. $iphoneCheckbox->addMultiOption("0","Lorem Ipsum")
  100. ->addMultiOption("1","Lorem Ipsum")
  101. ->addMultiOption("2","Lorem Ipsum")
  102. ->addMultiOption("3","Lorem Ipsum")
  103. ->setDecorators(array(
  104. array("viewScript",
  105. array(
  106. "viewScript"=>"_iphonecheckbox.phtml",
  107. 'class'=> "one_fourth",
  108. "postfix"=>"<hr>"
  109. ))));
  110.  
  111. $textArea = new Zend_Form_Element_Textarea("textarea");
  112. $textArea->setLabel("Textarea and WYSIWYG editor")
  113. ->setValue("Hi there! This is how a textarea looks with Hello! Admin Skin. Enjoy!")
  114. ->setDecorators(array(
  115. "Label",
  116. "ViewHelper",
  117. array("HtmlTag",array("tag"=>"div","class"=>"cleditorMain"))
  118. ));
  119.  
  120.  
  121. $submit = new Zend_Form_Element_Submit("submit");
  122. $submit->setDecorators(array("ViewHelper"));
  123.  
  124. $reset = new Zend_Form_Element_Submit("reset");
  125. $reset->setDecorators(array("ViewHelper"));
  126.  
  127.  
  128. $this->addElements(array($smallField,$mediumField,$largeField,$dateOfRegistration,$dropDown,
  129. $checkbox,$radioButton,$iphoneCheckbox,$textArea,$submit,$reset));
  130.  
  131.  
  132.  
  133.  
  134. $this->addDisplayGroup(array(
  135. 'smallField',"mediumField","largeField","dateOfRegistration","dropDown","checkBox",
  136. "radio","iphone","textarea","submit","reset"
  137. ),'group1',array("legend"=>"Legend here"));
  138.  
  139. $this->setDecorators(array(
  140. "FormElements",
  141. "Form"
  142. ));
  143. $this->setDisplayGroupDecorators(array(
  144. 'FormElements',
  145. "Fieldset",
  146.  
  147. ));
  148. }
  149.  
  150. public function callback($content, $element, array $options)
  151. {
  152. return '<h2>form title</h2>';
  153. }
  154. }
  155.  
  156. =========================================
  157. in _iphonecheckbox.phtml
  158. ========================================
  159. <?php
  160. $options = $this->element->getDecorator("ViewScript")->getOptions();
  161. if(isset($options['prefix']))
  162. {
  163. echo $options['prefix'];
  164. }
  165. ?>
  166. <div class="<?php echo $this->class ?>">
  167. <?php
  168. //echo $output = $this->element->renderViewHelper();
  169.  
  170. $element = $this->element;
  171. $type = "";
  172. foreach($element->getMultiOptions() as $key=>$value)
  173. {
  174. echo "<p><div class='iPhoneCheckContainer' style='width: 45px;'><input type='checkbox' class='iphone'><label class='iPhoneCheckLabelOff' style='width: 40px;'><span>off</span></label><label class='iPhoneCheckLabelOn' style='width: 0px;'><span style='margin-left: -26px;'>on</span></label><div class='iPhoneCheckHandle'></div></div><label class='fix'>$value</label></p>";
  175. }
  176. if(isset($options['postfix']))
  177. {
  178. echo $options['postfix'];
  179. }
  180. ?>
  181. </div>
Add Comment
Please, Sign In to add comment