当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Form::setDefaults方法代码示例

本文整理汇总了PHP中Zend_Form::setDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form::setDefaults方法的具体用法?PHP Zend_Form::setDefaults怎么用?PHP Zend_Form::setDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Form的用法示例。


在下文中一共展示了Zend_Form::setDefaults方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setDefaults

 public function setDefaults(array $defaults)
 {
     foreach ($defaults['tags'] as $tag) {
         $defaults['tag_' . $tag->id] = '1';
     }
     unset($defaults['tags']);
     return parent::setDefaults($defaults);
 }
开发者ID:kromeyer,项目名称:MMK-Newsroom,代码行数:8,代码来源:TagForm.php

示例2: testCanSetDefaultsForSubFormElementsFromFormWithArray

 public function testCanSetDefaultsForSubFormElementsFromFormWithArray()
 {
     $subForm = new Zend_Form_SubForm();
     $subForm->addElements(array('foo' => 'text', 'bar' => 'text'));
     $this->form->addSubForm($subForm, 'page1');
     $data = array('page1' => array('foo' => 'foo value', 'bar' => 'bar value'));
     $this->form->setDefaults($data);
     $this->assertEquals($data['page1']['foo'], $subForm->foo->getValue());
     $this->assertEquals($data['page1']['bar'], $subForm->bar->getValue());
 }
开发者ID:vicfryzel,项目名称:zf,代码行数:10,代码来源:FormTest.php

示例3: getForm

 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('text', 'name', array('label' => _('Name'), 'required' => true))->addElement('text', 'organisationUnit', array('label' => _('Organisation unit')))->addElement('text', 'website', array('label' => _('Website')))->addElement('text', 'email', array('label' => _('E-mail')))->addElement('text', 'streetAddress', array('label' => _('Street Address')))->addElement('text', 'locality', array('label' => _('Locality')))->addElement('text', 'postalCode', array('label' => _('Postal Code')))->addElement('text', 'countryName', array('label' => _('Country Name')))->addElement('checkbox', 'enableStatusesSystem', array('label' => _('Enable the statuses system for concepts. (check help below *)'), 'required' => false))->addElement('submit', 'submit', array('label' => _('Submit')));
         $form->getElement('email')->addValidator(new Zend_Validate_EmailAddress());
         $form->setDefaults($this->toArray());
     }
     return $form;
 }
开发者ID:olhsha,项目名称:OpenSKOS2tempMeertens,代码行数:14,代码来源:Tenant.php

示例4: getForm

 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('hidden', 'id', array('required' => $this->id ? true : false))->addElement('text', 'tenant', array('label' => _('Tenant'), 'readonly' => true, 'disabled' => true))->addElement('text', 'name', array('label' => _('Name'), 'required' => true))->addElement('text', 'email', array('label' => _('E-mail'), 'required' => true))->addElement('password', 'pw1', array('label' => _('Password'), 'maxlength' => 100, 'size' => 15, 'validators' => array(array('StringLength', false, array(4, 30)), array('identical', false, array('token' => 'pw2')))))->addElement('password', 'pw2', array('label' => _('Password (check)'), 'maxlength' => 100, 'size' => 15, 'validators' => array(array('identical', false, array('token' => 'pw1')))))->addElement('select', 'role', array('label' => _('Role'), 'required' => true))->addElement('radio', 'type', array('label' => _('Usertype'), 'required' => true))->addElement('text', 'apikey', array('label' => _('API Key (required for API users)'), 'required' => false))->addElement('text', 'eppn', array('label' => _('eduPersonPrincipalName (for SAML authentication)'), 'required' => false))->addElement('multiselect', 'defaultSearchProfileIds', array('label' => _('Search Profile Id'), 'required' => false))->addElement('checkbox', 'disableSearchProfileChanging', array('label' => _('Disable changing search profile'), 'required' => false))->addElement('submit', 'submit', array('label' => _('Submit')))->addElement('reset', 'reset', array('label' => _('Reset')))->addElement('submit', 'cancel', array('label' => _('Cancel')))->addElement('submit', 'delete', array('label' => _('Delete'), 'onclick' => 'return confirm(\'' . _('Are you sure you want to delete this user?') . '\');'))->addDisplayGroup(array('submit', 'reset', 'cancel', 'delete'), 'buttons');
         $form->getElement('type')->addMultiOptions(array_combine(OpenSKOS_Db_Table_Users::$types, OpenSKOS_Db_Table_Users::$types))->setSeparator(' ');
         $form->getElement('role')->addMultiOptions(array_combine(OpenSKOS_Db_Table_Users::$roles, OpenSKOS_Db_Table_Users::$roles));
         $searchProfilesModel = new OpenSKOS_Db_Table_SearchProfiles();
         $select = $searchProfilesModel->select();
         if (Zend_Auth::getInstance()->hasIdentity()) {
             $select->where('tenant=?', Zend_Auth::getInstance()->getIdentity()->tenant);
         }
         $searchProfiles = $searchProfilesModel->fetchAll($select);
         $searchProfilesOptions = array();
         foreach ($searchProfiles as $profile) {
             $searchProfilesOptions[$profile->id] = $profile->name;
         }
         $form->getElement('defaultSearchProfileIds')->addMultiOptions($searchProfilesOptions);
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueEmail'));
         $validator->setMessage(_("there is already a user with e-mail address '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('email')->addValidator($validator)->addValidator(new Zend_Validate_EmailAddress());
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueEppn'));
         $validator->setMessage(_("there is already a user with eduPersonPrincipalName '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('eppn')->addValidator($validator);
         $validator = new Zend_Validate_Callback(array($this, 'needApiKey'));
         $validator->setMessage(_("An API Key is required for users that have access to the API"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('type')->addValidator($validator, true);
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueApiKey'));
         $validator->setMessage(_("there is already a user with API key '%value%'"), Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('apikey')->addValidator(new Zend_Validate_Alnum())->addValidator($validator)->addValidator(new Zend_Validate_StringLength(array('min' => 6)));
         $userData = $this->toArray();
         $userData['defaultSearchProfileIds'] = explode(', ', $userData['defaultSearchProfileIds']);
         $form->setDefaults($userData);
         if (!$this->id || Zend_Auth::getInstance()->hasIdentity() && Zend_Auth::getInstance()->getIdentity()->id == $this->id) {
             $form->removeElement('delete');
             if (!OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed('editor.users', 'manage')) {
                 // Currently only password edit is allowed.
                 $form->removeElement('name');
                 $form->removeElement('email');
                 $form->removeElement('role');
                 $form->removeElement('type');
                 $form->removeElement('apikey');
                 $form->removeElement('eppn');
                 $form->removeElement('defaultSearchProfileIds');
                 $form->removeElement('disableSearchProfileChanging');
             }
         }
     }
     return $form;
 }
开发者ID:olhsha,项目名称:OpenSKOS2tempMeertens,代码行数:54,代码来源:User.php

示例5: setDefaults

 /**
  * Override setDefaults to dynamically generate subforms
  * Will add a subform per day that is present in the defaults data.
  * (Be sure to provide a day key, even if no tasks exist.
  * @param array $defaults
  */
 public function setDefaults($defaults)
 {
     // first add the subforms
     $this->clearSubForms();
     $dates = array_keys($defaults);
     foreach ($dates as $day) {
         $dayForm = new My_SubForm_TaskDay();
         $this->addSubForm($dayForm, (string) $day);
     }
     // set defaults, which will propagate to newly created subforms
     parent::setDefaults($defaults);
     // store keys in array for future use
     $this->defaultsKeys = array_keys($defaults);
 }
开发者ID:TBeijen,项目名称:Zend_Form_Dynamic,代码行数:20,代码来源:My_Form_TaskWeek.php

示例6: getForm

 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('text', 'name', array('label' => _('Name'), 'required' => true))->addElement('text', 'organisationUnit', array('label' => _('Organisation unit')))->addElement('text', 'website', array('label' => _('Website')))->addElement('text', 'email', array('label' => _('E-mail')))->addElement('text', 'streetAddress', array('label' => _('Street Address')))->addElement('text', 'locality', array('label' => _('Locality')))->addElement('text', 'postalCode', array('label' => _('Postal Code')))->addElement('text', 'countryName', array('label' => _('Country Name')))->addElement('submit', 'submit', array('label' => _('Submit')));
         $form->getElement('email')->addValidator(new Zend_Validate_EmailAddress());
         try {
             $form->getElement('postalCode')->addValidator(new Zend_Validate_PostCode());
         } catch (Zend_Validate_Exception $e) {
             //no valid locale found, so be it...
         }
         $form->setDefaults($this->toArray());
     }
     return $form;
 }
开发者ID:rubensworks,项目名称:OpenSKOS,代码行数:19,代码来源:Tenant.php

示例7: setDefaults

 /**
  * Set default values for elements
  *
  * If an element's name is not specified as a key in the array, its value
  * is set to null.
  *
  * @param  array $defaults
  * @return Zend_Form
  */
 public function setDefaults(array $defaults)
 {
     // Deal with Lupin_Form_Element_Group exclusively
     foreach ($this->getElements() as $name => $element) {
         if ($element instanceof Lupin_Form_Element_Group) {
             foreach ($element->getElements() as $el) {
                 $elName = $el->getName();
                 if (array_key_exists($elName, $defaults)) {
                     $el->setValue($defaults[$elName]);
                     $element->addElement($el);
                 }
             }
         }
     }
     return parent::setDefaults($defaults);
 }
开发者ID:jeremykendall,项目名称:spaz-api,代码行数:25,代码来源:Form.php

示例8: createForm

 /**
  * Creates a form for testing.
  *
  * The form contains a text element named "key" whose
  * value is set to "value".
  *
  * @return Zend_Form
  */
 protected function createForm()
 {
     $form = new Zend_Form();
     $form->addElement('text', 'key');
     $form->addElement('submit', 'send');
     $form->setDefaults(array('key' => 'value'));
     return $form;
 }
开发者ID:matthimatiker,项目名称:molcomponents,代码行数:16,代码来源:WebControllerTestCaseTest.php

示例9: getForm

 /**
  * @return Zend_Form
  */
 public function getForm()
 {
     static $form;
     if (null === $form) {
         $form = new Zend_Form();
         $form->addElement('hidden', 'id', array('required' => $this->id ? true : false))->addElement('text', 'code', array('label' => _('Code'), 'required' => true))->addElement('text', 'dc_title', array('label' => _('Title'), 'required' => true))->addElement('textarea', 'dc_description', array('label' => _('Description'), 'cols' => 80, 'row' => 5))->addElement('text', 'website', array('label' => _('Website')))->addElement('select', 'license', array('label' => _('Standard Licence'), 'style' => 'width: 450px;'))->addElement('text', 'license_name', array('label' => _('Custom Licence (name)')))->addElement('text', 'license_url', array('label' => _('Custom (URL)')))->addElement('checkbox', 'allow_oai', array('label' => _('Allow OpenSKOS OAI Harvesting')))->addElement('select', 'OAI_baseURL', array('label' => _('OAI baseURL'), 'style' => 'width: 450px;'))->addElement('text', 'conceptsBaseUrl', array('label' => _('Concepts base url'), 'style' => 'width: 450px;'))->addElement('submit', 'submit', array('label' => _('Submit')))->addElement('reset', 'reset', array('label' => _('Reset')))->addElement('submit', 'cancel', array('label' => _('Cancel')))->addElement('submit', 'delete', array('label' => _('Delete'), 'onclick' => 'return confirm(\'' . _('Are you sure you want to delete this collection and corresponding Concepts?') . '\');'))->addDisplayGroup(array('submit', 'reset', 'cancel', 'delete'), 'buttons');
         if (!$this->id) {
             $form->removeElement('delete');
         }
         $l = $form->getElement('license')->setOptions(array('onchange' => 'if (this.selectedIndex>0) {this.form.elements[\'license_name\'].value=this.options[this.selectedIndex].text; this.form.elements[\'license_url\'].value=this.options[this.selectedIndex].value; }'));
         $l->addMultiOption('', _('choose a standard license  or type a custom one:'), '');
         foreach (OpenSKOS_Db_Table_Collections::$licences as $key => $value) {
             $l->addMultiOption($value, $key);
         }
         $form->getElement('allow_oai')->setCheckedValue('Y')->setUncheckedValue('N');
         $validator = new Zend_Validate_Callback(array($this->getTable(), 'uniqueCode'));
         $validator->setMessage("code '%value%' already exists", Zend_Validate_Callback::INVALID_VALUE);
         $form->getElement('code')->addValidator($validator);
         $form->getElement('OAI_baseURL')->addValidator(new OpenSKOS_Validate_Url());
         $form->setDefaults($this->toArray());
         //load OAI sources:
         $oai_providers = array('' => _('Pick a provider (or leave empty)...'));
         $bootstrap = $this->_getBootstrap();
         $instances = $bootstrap->getOption('instances');
         if (null !== $instances) {
             foreach ($instances as $instance) {
                 switch ($instance['type']) {
                     case 'openskos':
                         //fetch Collections:
                         $client = new Zend_Http_Client($instance['url'] . '/api/collections');
                         $response = $client->setParameterGet('allow_oai', 'y')->setParameterGet('format', 'json')->request('GET');
                         if ($response->isError()) {
                             throw new Zend_Exception($response->getMessage(), $response->getCode());
                         }
                         foreach (json_decode($response->getBody())->collections as $collection) {
                             $uri = $instance['url'] . '/oai-pmh/?set=' . $collection->id;
                             $oai_providers[$uri] = $collection->dc_title;
                         }
                         break;
                     case 'external':
                         $uri = rtrim($instance['url'], '?/');
                         if ($instance['set'] || $instance['metadataPrefix']) {
                             $uri .= '?';
                         }
                         if ($instance['set']) {
                             $uri .= '&set=' . $instance['set'];
                         }
                         if ($instance['metadataPrefix']) {
                             $uri .= '&metadataPrefix=' . $instance['metadataPrefix'];
                         }
                         $oai_providers[$uri] = $instance['label'];
                         break;
                     default:
                         throw new Zend_Exception('Unkown OAI instance type: ' . $instance['type']);
                 }
             }
         }
         if (!isset($oai_providers[$this->OAI_baseURL])) {
             $oai_providers[$this->OAI_baseURL] = $this->OAI_baseURL;
         }
         $form->getElement('OAI_baseURL')->setMultiOptions($oai_providers);
     }
     return $form;
 }
开发者ID:rubensworks,项目名称:OpenSKOS,代码行数:67,代码来源:Collection.php

示例10: setSessionDefaults

 /**
  * Setting defaults
  * Values are written to session namespace & form is beeing populatet
  * 
  * @param array $values
  * @return Myself_Form_PageAble
  */
 public function setSessionDefaults(array $values)
 {
     parent::setDefaults($values);
     self::setMainForm($this);
     // Vorher alles rausschmeißen:
     $this->getNamespace()->unsetAll();
     foreach ($this->getSubForms() as $form) {
         $this->getNamespace()->{$form->getName()} = $form->getValues(true);
     }
     return $this;
 }
开发者ID:BowlingX,项目名称:Myself_Zend_Extensions,代码行数:18,代码来源:PageAble.php


注:本文中的Zend_Form::setDefaults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。