zend-form

Zend form and Zend filter HtmlEntities

我怕爱的太早我们不能终老 提交于 2019-12-07 22:07:20
问题 I have a registration form with a few fields. One of them looks like this: $first_name = new Zend_Form_Element_Text('first_name'); $first_name ->setLabel("First name") ->setRequired(true) ->addFilter(new Zend_Filter_HtmlEntities()); I use the same form for editing user's details. The problem is with the Zend_filter_HtmlEntities. It does the job when I send the form's data to the database, it replaces html special chars with their alternatives. However, when I initialise this form and give it

Where to place Zend_Forms, Controller? Model? Somewhere else?

こ雲淡風輕ζ 提交于 2019-12-07 22:01:56
问题 Where is it best to put the code for building my Zend_Forms? I used to put this logic inside my Controllers, but moved away from that after I needed to use the same form in different places. It meant I had to duplicate the creation of forms in different controllers. So I moved the form creation code into my Models. Does this seem right, it works for me. Or is there something I am missing, and they should in fact go somewhere else? 回答1: I usually put my form building code in separate files,

Add HTML placeholder into Zend_Form

别来无恙 提交于 2019-12-07 21:12:31
问题 I'm using Zend_Form for an application form using this code: class Form_ApplicationForm extends Zend_Form { public function init() { $this->setAction('/application/new') ->setMethod('post') ->setAttrib('id','application'); $name = new Zend_Form_Element_Text('name'); $name->setLabel('Your Name') ->setRequired(TRUE) ->addValidator('alpha', FALSE, array('allowWhiteSpace' => true)); $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email Address') ->setRequired(TRUE) ->addValidator(

Zend Forms - Element ID modification to allow re-use

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 19:15:06
问题 I have a Zend_Form object that I want to re-use several times in one page. The problem I'm having is that each time it's rendered it has the same element IDs. I've been unable to find a method for giving all the IDs a unique prefix or suffix each time I render the form. Complete Solution Subclass Zend_Form : class My_Form extends Zend_Form { protected $_idSuffix = null; /** * Set form and element ID suffix * * @param string $suffix * @return My_Form */ public function setIdSuffix($suffix) {

On submit the form don't display its POST data

人走茶凉 提交于 2019-12-07 18:21:37
I have a little experience with Zend Framework, but I like to fiddle with it until it works. But now I cannot resolve this problem. I have a form: <?php class Application_Form_Login extends Zend_Form { protected $notEmpty; public function init() { // Create NotEmpty validator $notEmpty = new Zend_Validate_NotEmpty(); // Configure validators for username element $notEmpty->setMessage('Gelieve dit veld in te vullen'); $this->setMethod('post'); // emailAddress $this->addElement('text', 'emailAddress', array( 'filters' => array('StringTrim', 'StringToLower'), 'required' => true, 'validators' =>

Can't set custom validator messages in Zend_Form

删除回忆录丶 提交于 2019-12-07 18:19:29
I just can't figure it out how to set custom validator messages in Zend_Form object. Here is an example code. $this->addElement('password', 'password', array( 'label' => 'Password', 'decorators' => array('ViewHelper'), 'filters' => array('StringTrim'), 'validators' => array( array('Digits', false, array('messages' => array('notDigits' => 'Only digits are allowed here'))) ), 'required' => true )); When I try to validate the form entering invalid data a message saying "notDigits" appear. I tried to change 'notDigits' to Zend_Validate_Digits::NOT_DIGITS, but it still doesn't work as expected. Any

Using “.” for decimals in zend validator float

微笑、不失礼 提交于 2019-12-07 17:47:44
问题 I have a form with a element called "price". I validate this element with the "float" validator. The thing is when I insert, for example: 12,50 => it is valid but when I try to save it on the DB (mysql) it is saved as "12.00" So I wanna to change the decimal character from "," to ".". Does anybody knows how?? Note. If I put: $price->addValidator('Float', 'de') or $validator = new Zend_Validate_Float(array('locale' => 'de')); $price->addValidator($validator) It does not work. 回答1: You can use

How to add CSS classes to Zend_Form_Element_Select option

六眼飞鱼酱① 提交于 2019-12-07 16:50:23
问题 I'm trying to add a CSS class to a Zend_Form_Element_Select option, but I just can't find a way to do it. The desired output would be something like this: <select name="hey" id="hey"> <option value="value1" style="parent">label1</option> <option value="value2" style="sibling">sublabel1</option> <option value="value3" style="sibling">sublabel2</option> <option value="value4" style="parent">label2</option> <option value="value5" style="sibling">sublabel3</option> <option value="value6" style=

How can I customise Zend_Form regex error messages?

一个人想着一个人 提交于 2019-12-07 10:55:37
问题 I have the following code: $postcode = $form->createElement('text', 'postcode'); $postcode->setLabel('Post code:'); $postcode->addValidator('regex', false, array('/^[a-z]{1,3}[0-9]{1,3} ?[0-9]{1,3}[a-z]{1,3}$/i')); $postcode->addFilters(array('StringToUpper')); $postcode->setRequired(true); It creates an input field in a form and sets a regex validation rule and works just fine. The problem is that the error message it displays when a user enters an invalid postcode is this: 'POSTCODE' does

Subscript or Superscript text within a Zend Form label

喜夏-厌秋 提交于 2019-12-07 09:05:46
问题 I would like to include subscript text in a Zend_Form_Element's label, and it doesn't seem to be working: $zend_form_element->setLabel('Label <sub>x</sub>'); Is there anything I can do to get it to output properly without having to manually write the form on the view page? Thanks for the help, Dave 回答1: I would say that best way is to get actual decorator from element and then set escape option, not to add new decorator: $zend_form_element->getDecorator('Label')->setOption('escape',false);