zend-form

Zend HTML5 Form element types

别等时光非礼了梦想. 提交于 2020-01-04 08:27:53
问题 Is there any easy way to get HTML5 Form elements into a Zend Form? createElement('tel','phone'); just doesn't work because zend doesn't support html5 form elements yet it seems... you can't override the type attribute either after it's been created. E.G. I need input type="tel/email/date/number" etc on my zend form. 回答1: Nevermind, I found this article: http://www.enrise.com/2010/12/html5-zend-framework-form-elements/. I just had to copy his code into my MVC architecture and it works now.

Zend Form Validating of required elements

五迷三道 提交于 2020-01-03 05:56:10
问题 I have the required element in my Zend Form: $name = new Zend_Form_Element_Text('name'); $name->setLabel('Name') ->setValue(isset($plan)?$plan['name']:'') ->setRequired() ->setAttribs(array('class' => 'required', 'maxlength' => 50)) ->addValidators(array(new Zend_Validate_StringLength(array('min' => 1, 'max' => 50)), new Zend_Validate_Db_NoRecordExists(array('table' => 'plan', 'field' => 'name'))) ->addFilters(array(new Zend_Filter_StringTrim, new Zend_Filter_StripTags)); All validators work

Zend: wrap FormErrors with user-defined html tags

梦想的初衷 提交于 2020-01-03 05:20:11
问题 Zend talk.By default,using the FormErrors decorator the generated list of errors has the following markup: <ul class="form-errors> <li> <b>[element label or name]</b> <ul> <li>[error message]</li> <li>[error message]</li> </ul> </li> </ul> Question: How can I use the following structure instead? <span class='myErrors'> •[error message]</br> </span> Update: I tried with: array('FormErrors', array( 'markupListStart' => "<span class='myErrors'>", 'markupListEnd' => '</span>',

Validating multiple optional form fields with Zend Framework

喜你入骨 提交于 2020-01-02 06:09:36
问题 I am trying to validate Zend_Form which has several optional fields and I want at least one of them to be filled in. In my case I have mobile, home and office phone numbers and I want at least one of them to be provided. I am trying to achieve this though Validation Context (as suggested here) by creating custom validator which extends Zend_Validate_Abstract. The problem is that if all optional fields are empty they are missing from the form $context (passed to the validator class) and this

Zend Form Element with Javascript - Decorator, View Helper or View Script?

风流意气都作罢 提交于 2020-01-02 05:57:49
问题 I want to add some javacsript to a Zend_Form_Element_Text . At first I thought a decorator would be the best way to do it, but since it is just a script (the markup doesn't change) then maybe a view helper is better? or a view script? It seems like they are all for the same purpose (regarding a form element). The javascript I want to add is not an event (e.g. change, click, etc.). I can add it easily with headScript() but I want to make it re-usable , that's why I thought about a decorator

Zend Form Validator Callback: How to exclude a username?

让人想犯罪 __ 提交于 2020-01-01 22:27:08
问题 I have written one function in User Mapper class userExist($username) which return true if same username does not exist in my database table. Now I want to use this function in the Add_User_Form class which extends Zend_Form. I want to use: $username = $this->createElement('text','username'); $username->setLabel('Username:') ->addValidator('Callback', true, array('callback'=>userExist???)); Can I use mapper class userExist($username) function as callback function? Please let me know if I am

Zend_Form - The mimetype of file 'foto.jpg' could not be detected

独自空忆成欢 提交于 2020-01-01 05:35:10
问题 I have a Zend_Form with file element like this: ->addElement('file', 'image', array( 'required' => false, 'label' => 'Venue Image', 'validators' => array( array('IsImage', false), array('Size', false, '2097152'), array('Upload', false), ), )) And when I'm using localhost the image is uploaded successfully. But when I move to my hosting the validation error shows for image field. The mimetype of file 'foto.jpg' could not be detected. What can be the reason of this? 回答1: same thing happened to

ZF2, how to create form view helper?

◇◆丶佛笑我妖孽 提交于 2019-12-31 03:31:07
问题 I want to change the way ZF2 shows the form elements. I think I have to create my own view helper but I don't know how. I Googled for it but didn't find any useful resource. 回答1: See the SourceCode of existing Zend\Form\View\Helper* Basically you extend those and overwrite the required functions of stuff you want to modify. After that you'll need to register your very own view helper. This is easily done within Module.php's getViewHelperConfig() public function getViewHelperConfig() { return

Button content in ZF2 forms

こ雲淡風輕ζ 提交于 2019-12-30 10:27:15
问题 How to edit the button content of a Button element (of a ZF2 form)? I can set a label, but i would like to insert some html code inside it. $this->add(array( 'type' => 'Button', 'name' => 'submit', 'options' => array( 'label' => 'Modifica', ), 'attributes' => array( 'type' => 'submit', 'class' => 'btn btn-warning' ) )); Thanks 回答1: You can simply use the disable_html_escape label's option. It works for me. $this->add(array( 'type' => 'Button', 'name' => 'submit', 'options' => array( 'label' =

Action View Helper in Zend - Work around?

无人久伴 提交于 2019-12-29 06:15:55
问题 I'm working on building up an interface that I want to function as a "tabbed browsing" sort of function. Each of these tabs has already been written as an action and the tabbed interface works fine as links to the individual tabs. I decided to try writing the "index" page for this controller - putting the content of all the tabs into hidden divs and swapping between them with jQuery, but once I started to use the action view helper - I ran into a lot of people saying that its bad practice.