/** Create assetstore form */
 public function createAssetstoreForm()
 {
     $form = new Zend_Form();
     $action = $this->webroot . '/assetstore/add';
     $form->setAction($action);
     $form->setName('assetstoreForm');
     $form->setMethod('post');
     $form->setAttrib('class', 'assetstoreForm');
     // Name of the assetstore
     $inputDirectory = new Zend_Form_Element_Text('name', array('label' => $this->t('Give a name'), 'id' => 'assetstorename'));
     $inputDirectory->setRequired(true);
     $form->addElement($inputDirectory);
     // Input directory
     $basedirectory = new Zend_Form_Element_Text('basedirectory', array('label' => $this->t('Pick a base directory'), 'id' => 'assetstoreinputdirectory'));
     $basedirectory->setRequired(true);
     $form->addElement($basedirectory);
     // Assetstore type
     $assetstoretypes = array('0' => $this->t('Managed by MIDAS'), '1' => $this->t('Remotely linked'));
     // Amazon support is not yet implemented, don't present it as an option
     //                          '2' => $this->t('Amazon S3'));
     $assetstoretype = new Zend_Form_Element_Select('assetstoretype', array('id' => 'assetstoretype'));
     $assetstoretype->setLabel('Select a type')->setMultiOptions($assetstoretypes);
     // Add a loading image
     $assetstoretype->setDescription('<div class="assetstoreLoading" style="display:none"><img src="' . $this->webroot . '/core/public/images/icons/loading.gif"/></div>')->setDecorators(array('ViewHelper', array('Description', array('escape' => false, 'tag' => false)), array('HtmlTag', array('tag' => 'dd')), array('Label', array('tag' => 'dt')), 'Errors'));
     $form->addElement($assetstoretype);
     // Submit
     $addassetstore = new Zend_Form_Element_Submit('addassetstore', $this->t('Add this assetstore'));
     $form->addElement($addassetstore);
     return $form;
 }
Exemple #2
0
 /** Main form */
 public function createMigrateForm($assetstores)
 {
     // Setup the form
     $form = new Zend_Form();
     $form->setAction('migratemidas2');
     $form->setName('migrateForm');
     $form->setMethod('post');
     $form->setAttrib('class', 'migrateForm');
     // Input directory
     $midas2_hostname = new Zend_Form_Element_Text('midas2_hostname', array('label' => $this->t('MIDAS2 Hostname'), 'size' => 60, 'value' => 'localhost'));
     $midas2_hostname->setRequired(true);
     $form->addElement($midas2_hostname);
     $midas2_port = new Zend_Form_Element_Text('midas2_port', array('label' => $this->t('MIDAS2 Port'), 'size' => 4, 'value' => '5432'));
     $midas2_port->setRequired(true);
     $midas2_port->setValidators(array(new Zend_Validate_Digits()));
     $form->addElement($midas2_port);
     $midas2_user = new Zend_Form_Element_Text('midas2_user', array('label' => $this->t('MIDAS2 User'), 'size' => 60, 'value' => 'midas'));
     $midas2_user->setRequired(true);
     $form->addElement($midas2_user);
     $midas2_password = new Zend_Form_Element_Password('midas2_password', array('label' => $this->t('MIDAS2 Password'), 'size' => 60, 'value' => 'midas'));
     $midas2_password->setRequired(true);
     $form->addElement($midas2_password);
     $midas2_database = new Zend_Form_Element_Text('midas2_database', array('label' => $this->t('MIDAS2 Database'), ' size' => 60, 'value' => 'midas'));
     $midas2_database->setRequired(true);
     $form->addElement($midas2_database);
     $midas2_assetstore = new Zend_Form_Element_Text('midas2_assetstore', array('label' => $this->t('MIDAS2 Assetstore Path'), 'size' => 60, 'value' => 'C:/xampp/midas/assetstore'));
     $midas2_assetstore->setRequired(true);
     $form->addElement($midas2_assetstore);
     // Button to select the directory on the server
     $midas2_assetstore_button = new Zend_Form_Element_Button('midas2_assetstore_button', $this->t('Choose'));
     $midas2_assetstore_button->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'class' => 'browse-button')), array('Label', array('tag' => 'div', 'style' => 'display:none'))));
     $form->addElement($midas2_assetstore_button);
     // Assetstore
     $assetstoredisplay = array();
     $assetstoredisplay[0] = $this->t('Choose one...');
     // Initialize with the first type (MIDAS)
     foreach ($assetstores as $assetstore) {
         if ($assetstore->getType() == 0) {
             $assetstoredisplay[$assetstore->getAssetstoreId()] = $assetstore->getName();
         }
     }
     $assetstore = new Zend_Form_Element_Select('assetstore');
     $assetstore->setLabel($this->t('MIDAS3 Assetstore'));
     $assetstore->setMultiOptions($assetstoredisplay);
     $assetstore->setDescription(' <a class="load-newassetstore" href="#newassetstore-form" rel="#newassetstore-form" title="' . $this->t('Add a new assetstore') . '"> ' . $this->t('Add a new assetstore') . '</a>')->setDecorators(array('ViewHelper', array('Description', array('escape' => false, 'tag' => false)), array('HtmlTag', array('tag' => 'dd')), array('Label', array('tag' => 'dt')), 'Errors'));
     $assetstore->setRequired(true);
     $assetstore->setValidators(array(new Zend_Validate_GreaterThan(array('min' => 0))));
     $assetstore->setRegisterInArrayValidator(false);
     // This array is dynamic so we disable the validator
     $form->addElement($assetstore);
     // Submit
     $submit = new Zend_Form_Element_Button('migratesubmit', $this->t('Migrate'));
     $form->addElement($submit);
     return $form;
 }
Exemple #3
0
 /**
  * Construct the bridge while setting the model.
  *
  * Extra parameters can be added in subclasses, but the first parameter
  * must remain the model.
  *
  * @param \MUtil_Model_ModelAbstract $model
  * @param \Zend_Form $form Rquired
  */
 public function __construct(\MUtil_Model_ModelAbstract $model, \Zend_Form $form = null)
 {
     $this->model = $model;
     $this->form = $form;
     if (!$form instanceof \Zend_Form) {
         throw new \MUtil_Model_ModelException("No form specified while create a form bridge for model " . $model->getName());
     }
     if (!$form->getName()) {
         $form->setName($model->getName());
     }
 }
Exemple #4
0
 public function testElementsRenderAsMembersOfSubFormsWithElementsBelongTo()
 {
     $this->form->setName('data')->setIsArray(true);
     $subForm = new Zend_Form_SubForm();
     $subForm->setElementsBelongTo('billing[info]');
     $subForm->addElement('text', 'name');
     $subForm->addElement('text', 'number');
     $this->form->addSubForm($subForm, 'sub');
     $html = $this->form->render($this->getView());
     $this->assertContains('name="data[billing][info][name]', $html);
     $this->assertContains('name="data[billing][info][number]', $html);
     $this->assertContains('id="data-billing-info-name"', $html);
     $this->assertContains('id="data-billing-info-number"', $html);
 }
 public function testRenderWithHidden()
 {
     $form = new Zend_Form();
     $form->setName('Test');
     $form->addElement('submit', 'Remove');
     $element = $form->createElement('hidden', 'Id');
     $element->setValue(10);
     $form->addElement($element);
     $decorator = new Application_Form_Decorator_RemoveButton();
     $decorator->setElement($form);
     $decorator->setSecondElement($element);
     $output = $decorator->render('content');
     // Output wird an content dran gehängt
     $this->assertEquals('content' . '<input type="hidden" name="Id" id="Id" value="10" />' . '<input type="submit" name="Remove" id="Remove" value="Remove" />', $output);
 }
 private function _getLoginForm()
 {
     $form = new Zend_Form();
     $form->setMethod('POST');
     $form->setName('userLoginForm');
     $username = new Zend_Form_Element_Text('username');
     $username->setLabel('User name')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('Alnum')->addValidator('StringLength', false, array(3, 24));
     $password = new Zend_Form_Element_Password('password');
     $password->setLabel('Password')->setRequired(true)->setValue(null)->addValidator('StringLength', false, array(6));
     $realm = new Zend_Form_Element_Select('realm');
     $realm->setLabel('Role')->addMultiOptions(array('user' => 'User', 'admin' => 'Admin'))->setRequired(true)->setValue('user');
     $rememberMe = new Zend_Form_Element_Checkbox('rememberMe');
     $rememberMe->setLabel('Remember Me');
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel('Login');
     $form->addElements(array($realm, $username, $password, $rememberMe, $submit));
     return $form;
 }
 public function getForm()
 {
     $db = $this->db;
     $form = new Zend_Form();
     $form->setAction('/Account');
     $form->setMethod('get');
     $form->setName('search');
     $accountName = $form->createElement('text', 'name');
     $accountName->setLabel('Name');
     $city = $form->createElement('text', 'city');
     $city->setLabel('City');
     $state = $form->createElement('text', 'state');
     $state->setLabel('State');
     $country = $form->createElement('text', 'country');
     $country->setLabel('Country');
     $assignedTo = new Zend_Dojo_Form_Element_FilteringSelect('assignedTo');
     $assignedTo->setLabel('Accounts assigned to')->setAutoComplete(true)->setStoreId('accountStore')->setStoreType('dojo.data.ItemFileReadStore')->setStoreParams(array('url' => '/user/jsonstore'))->setAttrib("searchAttr", "email")->setRequired(false);
     $branchId = new Zend_Dojo_Form_Element_FilteringSelect('branchId');
     $branchId->setLabel('Accounts Of Branch')->setAutoComplete(true)->setStoreId('branchStore')->setStoreType('dojo.data.ItemFileReadStore')->setStoreParams(array('url' => '/jsonstore/branch'))->setAttrib("searchAttr", "branch_name")->setRequired(false);
     $submit = $form->createElement('submit', 'submit')->setLabel('Search')->setAttrib("class", "submit_button");
     $form->addElements(array($name, $city, $assignedTo, $branchId, $submit));
     return $form;
 }
Exemple #8
0
 /**
  * Returns a Form builds from widget's form definition or instanciated from given classname
  *
  * Form definition:
  *
  * A widget can define one or more Form in its xml description file. A Form can be used, either as main output of
  * the widget, or on the dashboard screen for setting purpose. When you pass a Form name as argument, this method
  * will try to retrieve the associated Form definition and build the Form from it.
  *
  * Form class:
  *
  * It's also possible to pass an associative array where the key is a Form classname and the value, the path where
  * to find the file that contains the class. It this case, An instance of the class will be created and returned.
  *
  * Common treatment:
  *
  * In all cases, if the Form's target is the dashboard screen, a specific hidden field is added to it. Also, if the
  * Form has not submit element, it's automatically generated and added to it.
  *
  * Alternative way:
  *
  * The alternative way is to override this method in subclass and build your Form into it directly. Note that the
  * {@link iPMS_Widget::getForm()} method is used both to retrieve Form for main output of the widget, and the
  * dashboard screen.
  *
  * @throws iPMS_Widgets_Exception if form definition was not found
  * @throws iPMS_Widgets_Exception if form class was not found
  * @param string|array $form Either a Form name to build from  a Form's definition, or an array where the key is the
  * Form classname and the value, the path where to find it
  * @return Zend_Form a Zend_Form object
  */
 public function getForm($form)
 {
     if (is_string($form)) {
         // Form generated from Form definition
         if (isset($this->_formInstances[$form])) {
             return $this->_formInstances[$form];
         }
         $formDef = $this->getFormDefinition($form);
         if (!array_key_exists('type', $formDef['element'])) {
             $formDef = $formDef['element'];
         }
         $elementStack = array();
         foreach ($formDef as $elementDef) {
             /**
              * @var $element Zend_Form_Element|Zend_Form_Element_Select
              */
             $className = 'Zend_Form_Element_' . ucfirst($elementDef['type']);
             $element = new $className($elementDef['name'], array('label' => isset($elementDef['label']) ? $elementDef['label'] : '', 'value' => isset($elementDef['val']) ? $elementDef['val'] : '', 'helper' => 'form' . ucfirst($elementDef['type']), 'required' => isset($elementDef['required']) ? (int) $elementDef['required'] : 0));
             if ($elementDef['type'] == 'select') {
                 if (isset($elementDef['option'])) {
                     foreach ($elementDef['option'] as $option) {
                         $element->addMultiOptions(array($option['val'] => $option['label']));
                         if (isset($option['selected'])) {
                             $element->setValue($option['val']);
                         }
                     }
                 } elseif (isset($elementDef['callback'])) {
                     if (isset($elementDef['callback']['function'])) {
                         $options = call_user_func_array($elementDef['callback']['function'], (array) isset($elementDef['callback']['argument']) ? $elementDef['callback']['argument'] : array());
                         if ($elementDef['callback']['function'] == 'range') {
                             $options = array_combine($options, $options);
                         }
                         $element->addMultiOptions($options);
                         if (isset($elementDef['callback']['selected'])) {
                             $element->setValue($elementDef['callback']['selected']);
                         }
                     } else {
                         require_once 'iPMS/Widgets/Exception.php';
                         throw new iPMS_Widgets_Exception('Unable to generate element options from callback: function name not found');
                     }
                 } else {
                     require_once 'iPMS/Widgets/Exception.php';
                     throw new iPMS_Widgets_Exception('All select elements must have options');
                 }
             }
             if (isset($elementDef['id'])) {
                 // Optional CSS id for element
                 $element->setAttrib('id', $elementDef['id']);
             }
             if (isset($elementDef['class'])) {
                 // Optional CSS class for element
                 $element->setAttrib('class', $elementDef['class']);
             }
             if (isset($elementDef['filter'])) {
                 // Optional filter(s) for element
                 $element->addFilters((array) $elementDef['filter']);
             }
             // Optional validator for element
             if (isset($elementDef['validator'])) {
                 // Optional validator for element
                 $element->addValidators((array) $elementDef['validator']);
             }
             $elementStack[] = $element;
         }
         // Creating new form instance
         $formInstance = new Zend_Form();
         $formInstance->setName($form)->setElementsBelongTo($form)->addElements($elementStack);
         // Optional description for the Form
         if (isset($formDef['description'])) {
             $formInstance->setDescription($formDef['description'])->addDecorator('Description', array('placement' => 'prepend'));
         }
     } elseif (is_array($form) && isset($form['clasname'])) {
         // Form generated from specific class
         $className = $form['clasname'];
         if (isset($this->_formInstances[$className])) {
             return $this->_formInstances[$className];
         }
         if (!class_exists($className)) {
             require_once 'Zend/Loader.php';
             Zend_Loader::loadClass($className, isset($form['path']) ? isset($form['path']) : null);
         }
         $formInstance = new $className();
         if (!$formInstance instanceof Zend_Form) {
             require_once 'iPMS/Widgets/Exception.php';
             throw new iPMS_Widgets_Exception(sprintf('Invalid argument: Detected class "%s", which is not an instance of Zend_Form', $className));
         }
     } else {
         require_once 'iPMS/Widgets/Exception.php';
         throw new iPMS_Widgets_Exception('Invalid argument $form');
     }
     // Common treatment
     if ($form !== 'dashboard') {
         $hidden = new Zend_Form_Element_Hidden('widgetUpdate');
         $hidden->setValue($this . '_' . $this->_id)->setRequired(true);
         $hidden->getDecorator('HtmlTag')->setOption('class', 'hidden');
         $hidden->getDecorator('Label')->setOption('tagClass', 'hidden');
         $formInstance->addElement($hidden);
     }
     // Add a submit element if it doesn't already defined
     if (null === $formInstance->getElement('submit')) {
         $submit = new Zend_Form_Element_Submit('submit');
         $submit->setLabel('submit');
         $formInstance->addElement($submit);
     }
     return $this->_formInstances[isset($className) ? $className : $form] = $formInstance;
 }
 /**
  * Add a form group/subform
  *
  * @param  Zend_Form $form
  * @param  string $name
  * @param  int $order
  * @return Zend_Form
  */
 public function addSubForm(Zend_Form $form, $name, $order = null)
 {
     $name = (string) $name;
     foreach ($this->_loaders as $type => $loader) {
         $loaderPaths = $loader->getPaths();
         foreach ($loaderPaths as $prefix => $paths) {
             foreach ($paths as $path) {
                 $form->addPrefixPath($prefix, $path, $type);
             }
         }
     }
     if (!empty($this->_elementPrefixPaths)) {
         foreach ($this->_elementPrefixPaths as $spec) {
             list($prefix, $path, $type) = array_values($spec);
             $form->addElementPrefixPath($prefix, $path, $type);
         }
     }
     if (!empty($this->_displayGroupPrefixPaths)) {
         foreach ($this->_displayGroupPrefixPaths as $spec) {
             list($prefix, $path) = array_values($spec);
             $form->addDisplayGroupPrefixPath($prefix, $path);
         }
     }
     if (null !== $order) {
         $form->setOrder($order);
     }
     $form->setName($name);
     $this->_subForms[$name] = $form;
     $this->_order[$name] = $order;
     $this->_orderUpdated = true;
     return $this;
 }
<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');
/**
 * @file form.php
 */
// Load Zend Framework
set_include_path(implode(PATH_SEPARATOR, array(get_include_path(), __DIR__ . '/')));
// Create the auto loader so zend can load the rest automatically
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$form = new Zend_Form();
// Set form name, id, method and action
$form->setName('fileUpload')->setAttrib('id', 'fileUpload')->setMethod('post')->setAttrib('enctype', 'multipart/form-data')->setAction('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
$file = new Zend_Form_Element_File('file');
$file->setLabel('File')->setRequired(true)->setValueDisabled(False)->addValidator('Extension', FALSE, 'jpg,jpeg')->addValidator('Size', false, array('min' => 20, 'max' => 20000000));
$file->getValidator('Extension')->setMessage('JPEGs only');
// Create text area for message
$message = new Zend_Form_Element_Textarea('message');
$message->setRequired(TRUE)->setAttrib('id', 'message')->addErrorMessage('Please specify a message');
// Create a submit button
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Submit')->setAttrib('id', 'submit');
// Set the ViewScript decorator for the form and tell it which
// template file to use
$form->setDecorators(array(array('ViewScript', array('viewScript' => 'form-contact.tpl.php'))));
// Add the form elements AFTER the viewscript decorator has been set
$form->addElements(array($file, $message, $submit));
// Get rid of all element decorators except for ViewHelper to render
// the individual elements and Errors decorator to render the errors.
Exemple #11
0
 /** Main form */
 public function createImportForm($assetstores)
 {
     // Setup the form
     $form = new Zend_Form();
     $form->setAction('import/import');
     $form->setName('importForm');
     $form->setMethod('post');
     $form->setAttrib('class', 'importForm');
     /** @var RandomComponent $randomComponent */
     $randomComponent = MidasLoader::loadComponent('Random');
     // Hidden upload id
     $uploadId = new Zend_Form_Element_Hidden('uploadid', array('value' => $randomComponent->generateInt()));
     $uploadId->setDecorators(array('ViewHelper', array('HtmlTag', array('style' => 'display:none')), array('Label', array('style' => 'display:none'))));
     $form->addElement($uploadId);
     // Input directory
     $inputDirectory = new Zend_Form_Element_Text('inputdirectory', array('label' => $this->t('Directory on the server'), 'id' => 'inputdirectory', 'size' => 60));
     $inputDirectory->setRequired(true);
     $form->addElement($inputDirectory);
     // Button to select the directory on the server
     $inputDirectoryButton = new Zend_Form_Element_Button('inputdirectorybutton', $this->t('Choose'));
     $inputDirectoryButton->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'class' => 'browse-button')), array('Label', array('tag' => 'div', 'style' => 'display:none'))));
     $form->addElement($inputDirectoryButton);
     // Select the assetstore type
     $assetstoretypes = array();
     $assetstoretypes[MIDAS_ASSETSTORE_LOCAL] = $this->t('Copy data on this server');
     // manage by MIDAS
     $assetstoretypes[MIDAS_ASSETSTORE_REMOTE] = $this->t('Link data from its current location');
     // link the data
     $assetstoretype = new Zend_Form_Element_Select('importassetstoretype');
     $assetstoretype->setLabel($this->t('Storage type'));
     $assetstoretype->setMultiOptions($assetstoretypes);
     $assetstoretype->setAttrib('onChange', 'assetstoretypeChanged()');
     $form->addElement($assetstoretype);
     // Assetstore
     $assetstoredisplay = array();
     $assetstoredisplay[0] = $this->t('Choose one...');
     // Initialize with the first type (MIDAS)
     foreach ($assetstores as $assetstore) {
         if ($assetstore->getType() == 0) {
             $assetstoredisplay[$assetstore->getAssetstoreId()] = $assetstore->getName();
         }
     }
     $assetstore = new Zend_Form_Element_Select('assetstore');
     $assetstore->setLabel($this->t('Assetstore'));
     $assetstore->setMultiOptions($assetstoredisplay);
     $assetstore->setDescription(' <a class="load-newassetstore" href="#newassetstore-form" rel="#newassetstore-form" title="' . $this->t('Add a new assetstore') . '"> ' . $this->t('Add a new assetstore') . '</a>')->setDecorators(array('ViewHelper', array('Description', array('escape' => false, 'tag' => false)), array('HtmlTag', array('tag' => 'dd')), array('Label', array('tag' => 'dt')), 'Errors'));
     $assetstore->setRequired(true);
     $assetstore->setValidators(array(new Zend_Validate_GreaterThan(array('min' => 0))));
     $assetstore->setRegisterInArrayValidator(false);
     // This array is dynamic so we disable the validator
     $form->addElement($assetstore);
     // Import empty directories
     $emptydirs = new Zend_Form_Element_Checkbox('importemptydirectories');
     $emptydirs->setLabel($this->t('Import empty directories'))->setChecked(true);
     $form->addElement($emptydirs);
     // Where to import the data
     $importFolder = new Zend_Form_Element_Text('importFolder', array('label' => $this->t('Folder Id'), 'id' => 'importFolder', 'size' => 3, 'value' => 1));
     $importFolder->setRequired(true);
     $form->addElement($importFolder);
     // Hidden filed to pass the translation of the stop import
     $stopimport = new Zend_Form_Element_Hidden('importstop', array('value' => $this->t('Stop import')));
     $stopimport->setDecorators(array('ViewHelper', array('HtmlTag', array()), array('Label', array()), 'Errors'));
     $form->addElement($stopimport);
     // Submit
     $submit = new Zend_Form_Element_Button('importsubmit', $this->t('Import data'));
     $form->addElement($submit);
     return $form;
 }
<?php

/**
 * @file form.php
 */
// Load Zend Framework
set_include_path(implode(PATH_SEPARATOR, array(get_include_path(), __DIR__ . '/')));
// Create the auto loader so zend can load the rest automatically
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$form = new Zend_Form();
// Set form name, id, method and action
$form->setName('contact')->setAttrib('id', 'form-contact')->setMethod('post')->setAction('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
// Create text box for name
$name = new Zend_Form_Element_Text('name');
$name->setRequired(TRUE)->setAttrib('id', 'fullname')->addErrorMessage('Please provide your name');
// Create text box for email
$email = new Zend_Form_Element_Text('email');
$email->setRequired(TRUE)->setAttrib('id', 'email')->addErrorMessage('Please provide a valid e-mail address');
// Create text area for message
$message = new Zend_Form_Element_Textarea('message');
$message->setRequired(TRUE)->setAttrib('id', 'message')->addErrorMessage('Please specify a message');
// Create a submit button
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Send Your Message!')->setAttrib('id', 'submit');
// Set the ViewScript decorator for the form and tell it which
// template file to use
$form->setDecorators(array(array('ViewScript', array('viewScript' => 'form-contact.tpl.php'))));
// Add the form elements AFTER the viewscript decorator has been set
$form->addElements(array($name, $email, $message, $submit));
// Get rid of all element decorators except for ViewHelper to render
 /**
  * @group ZF-10679
  */
 public function testFieldsetIdOverridesFormId()
 {
     $form = new Zend_Form();
     $form->setName('bar')->setAttrib('id', 'form-id')->setView($this->getView());
     $html = $this->decorator->setElement($form)->setOption('id', 'fieldset-id')->render('content');
     $this->assertContains('<fieldset id="fieldset-id"', $html);
 }
Exemple #14
0
		function setForm()
		{
			$form=new Zend_Form();
			$form->setMethod('post');
			$form->setName('insertForm');
			$form->setAction($this->view->baseUrl().'/admin/tintuc/insert');
			
			$form->addElement('text','news_title');
			$news_login=$form->getElement('news_title');
			$news_login->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Tiêu đề không được để trống'));;
			$news_login->removeDecorator('HtmlTag')->removeDecorator('Label');
			
			$el=$form->createElement('textarea','news_avatar', array('style'=>'height:100px'));
			$el->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Avatar không được để trống'));
			$el->setAttrib('id', 'news_avatar');
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			$form->addElement($el);
			
			$el=$form->createElement('textarea','news_summary', array('style'=>'height:100px'));
			$el->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Mục tóm tắt không được để trống'));
			$el->setAttrib('id', 'news_summary');
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			$form->addElement($el);
			
			$el=$form->createElement('textarea','news_content', array('style'=>'height:300px'));
			$el->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Nội dung không được để trống'));;
			$el->setAttrib('id', 'news_content');
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			$form->addElement($el);
			
			$form->addElement('text','news_author');
			$el=$form->getElement('news_author');
			$el->setValue($_SESSION['user']);
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			
			$form->addElement('text','news_post_date');
			$el=$form->getElement('news_post_date');
			$el->setAttrib('class', 'datepicker');
			$el->setValue(date("Y-m-d",time()+7*3600));
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			
			$form->addElement('text','news_modified_date');
			$el=$form->getElement('news_modified_date');
			$el->setAttrib('class', 'datepicker');
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			
			if ($_SESSION['role_id']==0) {
				$el=$form->createElement('select', 'news_status', array('multioptions'=>array('Chưa duyệt'=>'Chưa duyệt',
																						'Đã duyệt'=>'Đã duyệt',
																						'Riêng tư'=>'Riêng tư',
																						'Công khai'=>'Công khai')));
			} else if ($_SESSION['role_id']==1) {
				$el=$form->createElement('select', 'news_status', array('multioptions'=>array(	'Đã duyệt'=>'Đã duyệt',
																								'Riêng tư'=>'Riêng tư',
																								'Công khai'=>'Công khai')));
			} else {
				$el=$form->createElement('select', 'news_status', array('multioptions'=>array(	'Chưa duyệt'=>'Chưa duyệt',
																								'Đã duyệt'=>'Đã duyệt')));
			}
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			$form->addElement($el);
			
			$is_hot= new Zend_Form_Element_Radio('is_hot');
			$is_hot->setRequired(true)
				->setLabel('Is hot?')
				->setMultiOptions(array(
                                                                      "0" => "Không",
                                                                      "1" => "Có"));
																	  
			$is_hot->removeDecorator('HtmlTag')->removeDecorator('Label');
			$form->addElement($is_hot);
			
			$listarray=array();
			if ($_SESSION['role_id']==0)
			{
				$listCategories=$this->mdanhmuc->getListCM();
				foreach ($listCategories as $category)
				{
					if ($this->mtintuc->countChildById($category['category_id'])==0)
						$listarray[$category['category_id']]=$category['category_name'];
				}
			}
			else 
			{
				$userID=$_SESSION['user_id'];
				$categoriesId=$this->mtintuc->getCategoryIDByUserId($userID);
				foreach ($categoriesId as $categoryId)
				{
					$category=$this->mtintuc->getCategoryById($categoryId);
					if ($this->mtintuc->countChildById($category['category_id'])==0)
						$listarray[$category['category_id']]=$category['category_name'];
				}
			}
			
			$el=$form->createElement("select","category_id",array(
                                                 "multioptions"=> $listarray));
			$el->removeDecorator('HtmlTag')->removeDecorator('Label');
			$form->addElement($el);
			
			return $form;
		}
Exemple #15
0
 public function testNameAttributeOutputForXhtml()
 {
     // Create form
     $form = new Zend_Form();
     $form->setName('foo');
     $form->setMethod(Zend_Form::METHOD_GET);
     $form->removeDecorator('HtmlTag');
     // Set doctype
     $this->getView()->getHelper('doctype')->doctype(Zend_View_Helper_Doctype::XHTML1_STRICT);
     $expected = '<form id="foo" method="get" action="">' . PHP_EOL . '</form>';
     $this->assertSame($expected, $form->render($this->getView()));
 }
Exemple #16
0
 public function getForm()
 {
     $form = new Zend_Form();
     $form->setName($this->poClass . "_form");
     $schema = $this->schema->getSchema();
     foreach ($this->getEditableProperties() as $propertyName => $property) {
         $methodName = 'get' . ucfirst($propertyName) . 'Element';
         if (method_exists($this, $methodName)) {
             $form->addElement($this->{$methodName}());
             continue;
         }
         $dbField = $schema[$this->poDef->table]->fields[$property->columnName];
         $dbType = $dbField->type;
         switch ($dbType) {
             case 'integer':
             case 'timestamp':
             case 'boolean':
                 $element = new Zend_Form_Element_Text($propertyName);
                 $element->addValidator('allnum');
                 $element->addFilter('int');
                 break;
             case 'float':
             case 'decimal':
                 $element = new Zend_Form_Element_Text($propertyName);
                 break;
             case 'blob':
             case 'clob':
                 $element = new Zend_Form_Element_Textarea($propertyName);
                 break;
             case 'text':
             case 'time':
             case 'date':
             default:
                 $element = new Zend_Form_Element_Text($propertyName);
                 break;
         }
         if (list($relatedClassName, $relationDef) = $this->isFK($property->columnName)) {
             $element = new Zend_Form_Element_Select($propertyName);
             $pos = ezcPersistentSessionInstance::get();
             $q = $pos->createFindQuery($relatedClassName);
             $this->queryHook($q);
             $list = $pos->find($q, $relatedClassName);
             $element->options = $list;
             $element->addFilter('int');
         }
         if (!$this->isNullProperty($property->columnName, $this->poDef->table)) {
             $element->setRequired(true)->addValidator('NotEmpty');
         }
         $element->setLabel($propertyName);
         $form->addElement($element);
     }
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel('Submit');
     $form->addElement($submit);
     $form->clearDecorators();
     $form->addDecorator('FormElements')->addDecorator('HtmlTag', array('tag' => '<ul>'))->addDecorator('Form');
     $form->setElementDecorators(array(array('ViewHelper'), array('Errors'), array('Description'), array('Label', array('separator' => ' ')), array('HtmlTag', array('tag' => 'li', 'class' => 'element-group'))));
     // buttons do not need labels
     $submit->setDecorators(array(array('ViewHelper'), array('Description'), array('HtmlTag', array('tag' => 'li', 'class' => 'submit-group'))));
     $form->setView(new Zend_View());
     return $form;
 }