Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Application_Form_Custom extends Zend_Form
- {
- public function __construct($options = null) {
- parent::__construct($options);
- $this->addElementPrefixPath('Shayan_Decorators',
- 'Shayan/Decorators/',
- 'decorator');
- $smallField = new Zend_Form_Element_Text("smallField");
- $smallField->setLabel("small field")
- ->setRequired(true)
- ->setValue("Small input field")
- ->setDescription("Field Description")
- ->setAttrib("class", "sf")
- ->setDecorators(array("Element",
- array(
- // Decorator name
- 'Callback',
- // Options
- array(
- 'callback' => array($this,"callback"),
- 'placement' => 'prepend',
- )
- ),
- ));
- $mediumField = new Zend_Form_Element_Text("mediumField");
- $mediumField->setLabel("Medium field")
- ->setRequired(true)
- ->setValue("medium input field")
- ->setDescription("A positive message!")
- ->setAttrib("class", "mf")
- ->setDecorators(array("Element"));
- $largeField = new Zend_Form_Element_Text("largeField");
- $largeField->setLabel("Large field")
- ->setRequired(true)
- ->setValue("large input field")
- ->setDescription("A negative message!")
- ->setAttrib("class", "lf")
- ->setDecorators(array("Element"));
- $dateOfRegistration = new ZendX_JQuery_Form_Element_DatePicker(
- 'dateOfRegistration',
- array('jQueryParams' => array('dateFormat' => 'yy-mm-dd')));
- $dateOfRegistration->setLabel('Date Picker')
- ->addFilter('StripTags')
- ->addFilter('StringTrim')
- ->addValidator('Date')
- ->setDecorators(array(
- array('UiWidgetElement', array('tag' => '')),
- "Label",
- array("HtmlTag",array("tag"=>"<p>"))
- ));
- $dropDown = new Zend_Form_Element_Select("dropDown");
- $dropDown->setLabel("DropDown")
- ->addMultiOption("0","Select an option")
- ->addMultiOption("1","Upload")
- ->addMultiOption("2","Change")
- ->addMultiOption("3","Remove")
- ->setAttrib("class","dropdown")
- ->setDecorators(array("Element",
- array(array('HR' => 'HtmlTag'), array('tag' => '<hr>', 'placement' => 'append'))
- ));
- $checkbox = new Zend_Form_Element_MultiCheckbox("checkBox");
- $checkbox->setLabel("Normal Radio / Checkboxes")
- ->addMultiOption("0","Lorem Ipsum")
- ->addMultiOption("1","Lorem Ipsum")
- ->addMultiOption("2","Lorem Ipsum")
- ->addMultiOption("3","Lorem Ipsum")
- ->setDecorators(array(
- array("viewScript",
- array(
- "viewScript"=>"_multicheckbox.phtml",
- 'class'=> "one_fourth",
- "prefix"=>"<div class='one_half'><h2>Normal Radio / Checkboxes</h2></div>
- <div class='one_half_last'><h2>Iphone Checkboxes</h2></div>
- <div class='clearboth'></div>",
- ))));
- $radioButton = new Zend_Form_Element_Radio("radio");
- $radioButton->addMultiOption("0","Lorem Ipsum")
- ->addMultiOption("1","Lorem Ipsum")
- ->addMultiOption("2","Lorem Ipsum")
- ->addMultiOption("3","Lorem Ipsum")
- ->setDecorators(array(
- array("viewScript",
- array(
- "viewScript"=>"_multicheckbox.phtml",
- 'class'=> "one_fourth"
- ))));
- $iphoneCheckbox = new Zend_Form_Element_MultiCheckbox("iphone");
- $iphoneCheckbox->addMultiOption("0","Lorem Ipsum")
- ->addMultiOption("1","Lorem Ipsum")
- ->addMultiOption("2","Lorem Ipsum")
- ->addMultiOption("3","Lorem Ipsum")
- ->setDecorators(array(
- array("viewScript",
- array(
- "viewScript"=>"_iphonecheckbox.phtml",
- 'class'=> "one_fourth",
- "postfix"=>"<hr>"
- ))));
- $textArea = new Zend_Form_Element_Textarea("textarea");
- $textArea->setLabel("Textarea and WYSIWYG editor")
- ->setValue("Hi there! This is how a textarea looks with Hello! Admin Skin. Enjoy!")
- ->setDecorators(array(
- "Label",
- "ViewHelper",
- array("HtmlTag",array("tag"=>"div","class"=>"cleditorMain"))
- ));
- $submit = new Zend_Form_Element_Submit("submit");
- $submit->setDecorators(array("ViewHelper"));
- $reset = new Zend_Form_Element_Submit("reset");
- $reset->setDecorators(array("ViewHelper"));
- $this->addElements(array($smallField,$mediumField,$largeField,$dateOfRegistration,$dropDown,
- $checkbox,$radioButton,$iphoneCheckbox,$textArea,$submit,$reset));
- $this->addDisplayGroup(array(
- 'smallField',"mediumField","largeField","dateOfRegistration","dropDown","checkBox",
- "radio","iphone","textarea","submit","reset"
- ),'group1',array("legend"=>"Legend here"));
- $this->setDecorators(array(
- "FormElements",
- "Form"
- ));
- $this->setDisplayGroupDecorators(array(
- 'FormElements',
- "Fieldset",
- ));
- }
- public function callback($content, $element, array $options)
- {
- return '<h2>form title</h2>';
- }
- }
- =========================================
- in _iphonecheckbox.phtml
- ========================================
- <?php
- $options = $this->element->getDecorator("ViewScript")->getOptions();
- if(isset($options['prefix']))
- {
- echo $options['prefix'];
- }
- ?>
- <div class="<?php echo $this->class ?>">
- <?php
- //echo $output = $this->element->renderViewHelper();
- $element = $this->element;
- $type = "";
- foreach($element->getMultiOptions() as $key=>$value)
- {
- 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>";
- }
- if(isset($options['postfix']))
- {
- echo $options['postfix'];
- }
- ?>
- </div>
Add Comment
Please, Sign In to add comment