zend-form

Zend EmailAddress Validation returning multiple errors

回眸只為那壹抹淺笑 提交于 2019-12-01 08:25:52
问题 I am unable to make Zend_Validate_EmailAddress show only 1 error message when the user enter invalid email address. The code is $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email: ') ->addFilter('StringTrim') ->addFilter('StripTags') ->addValidator('EmailAddress',true, array(... error msgs ...)) ->addValidator(new Zend_Validate_Db_NoRecordExists(array( ... db + table + col details ... ),true, array(... error msgs ...))) ->setRequired(true); $this->addElement($email); And

Handling dependencies in Zend Framework 2 Forms

半城伤御伤魂 提交于 2019-12-01 06:37:13
I am trying to build a form in ZF2. The problem comes when I want to populate the options array of a Select input element from a database table. A response to this question Zend FrameWork 2 Get ServiceLocator In Form and populate a drop down list by @timdev pointed me to the ZF2 docs where the 'correct' method is described. I followed this carefully but I suspect that they must have left obvious code out assuming I could fill in the gaps as I cannot get it to work. Can anyone see what I am doing wrong? I start with a form to which I add a fieldset: namespace Ctmm\Form; use Zend\Form\Form;

How to use DoctrineModule\Validator\NoObjectExists in edit forms - Zend Framework 2 & Doctrine 2

北战南征 提交于 2019-12-01 06:06:37
问题 What is the most effective way to use DoctrineModule\Validator\NoObjectExists validator in a Zend Form that is used for editing also? Because when I use the same Form for saving edited values, this validates the Object existence and flags form is invalid. 回答1: Few weeks ago I resolved the same problem using a helper method in my custom filter. I am not sure if this is the correct approach but it works. Write a custom inputfilter extending Zend\InputFilter\InputFilter . Add your generic

array input like name=“person[]” in zend form

陌路散爱 提交于 2019-12-01 01:32:31
问题 In normal html, we could have an array field like person[] <input name="person[]" type="text" /> <input name="person[]" type="text" /> <input name="person[]" type="text" /> As far as I know, Zend_Form doesn't have that. I read another answer that suggested it could be done using a decorator that would add the [] at the right place. This is the code for that specific question $html = ''; // some code html $i = 0; foreach ($element->getMultiOptions() as $value => $label){ $html .= '<input type=

Zend Framework 2 - Annotation Forms don't work

我怕爱的太早我们不能终老 提交于 2019-11-30 23:56:56
Thanks to @Hikaru-Shindo I looked into AnnotationForms which seem to be the best available as a work-around for ModelForms . But the example shown here doesn't work for me. use Zend\Form\Annotation\AnnotationBuilder; $builder = new AnnotationBuilder(); $form = $builder->createForm('User'); Looking at this code I wonder where the AnnotationBuilder knows where to look for this user form. Especially because in the annotation in the form def there is a lowercase 'user' @Annotation\Name("user") I put the form def code into 'MyModule/Form/UserForm.php' and the lower code into my Controller. Is this

zend form for multicheckbox remove input from labels

孤人 提交于 2019-11-30 23:54:44
I am using zend_form (part of Zend Framwork) to create a form and found when I add a set of checkboxes using Zend_Form's multicheckbox element (Zend_Form_Element_MultiCheckbox) the code that is outputted like so: <label for="subjects-maths"> <input type="checkbox" value="maths" id="subjects-maths" name="subjects[]"> Maths </label> <label for="subjects-english"> <input type="checkbox" value="maths" id="subjects-english" name="subjects[]"> English </label> I.e. the input is inside the label. Whereas the code is technically ok it is against good practice as far as the W3c see it and is also not

How would I format Zend_Form_Element_Radio so the label follows the input?

心不动则不痛 提交于 2019-11-30 20:58:41
The default decorator for the Zend_Form_Element_Radio is <label for="type_id-1"><input type="radio" name="type_id" id="type_id-1" value="1">Pack</label> The label tag wraps the input tag. Instead I would like to to look like <input type="radio" name="type_id" id="type_id-1" value="1"><label for="type_id-1">Pack</label> I thought it might have to do with the "Label" of the element, but that is different. Even with the following code, I still get the label wrapping the radio. When I use this form code. public function init() { parent::init(); $this->setName('createdomain'); $type_id = new Zend

Zend Framework 2 - Annotation Forms don't work

梦想与她 提交于 2019-11-30 18:07:36
问题 Thanks to @Hikaru-Shindo I looked into AnnotationForms which seem to be the best available as a work-around for ModelForms . But the example shown here doesn't work for me. use Zend\Form\Annotation\AnnotationBuilder; $builder = new AnnotationBuilder(); $form = $builder->createForm('User'); Looking at this code I wonder where the AnnotationBuilder knows where to look for this user form. Especially because in the annotation in the form def there is a lowercase 'user' @Annotation\Name("user") I

Zend Framework 2 - Translate Standard Form Validation and Error messages

给你一囗甜甜゛ 提交于 2019-11-30 15:36:26
I'm writing a complete German application and therefore need to set basically everything to German. My question: What is the best and easiest way to set for example the form validation to German? I found this page but couldn't figure out how to get this code working: Zend_Validate_Abstract::setDefaultTranslator($translate); Could anyone give me some advice how to use this? Edit: Thanks to @Gordon I put the following into my Application/Module.php: use Zend\I18n\Translator\Translator; use Zend\Validator\AbstractValidator; class Module { public function onBootstrap(MvcEvent $e) { ... $translator

Password Confirmation in zend framework

浪子不回头ぞ 提交于 2019-11-30 15:31:25
I add this class to library/My/Validate/PasswordConfirmation.php <?php require_once 'Zend/Validate/Abstract.php'; class My_Validate_PasswordConfirmation extends Zend_Validate_Abstract { const NOT_MATCH = 'notMatch'; protected $_messageTemplates = array( self::NOT_MATCH => 'Password confirmation does not match' ); public function isValid($value, $context = null) { $value = (string) $value; $this->_setValue($value); if (is_array($context)) { if (isset($context['password']) && ($value == $context['password'])) { return true; } } elseif (is_string($context) && ($value == $context)) { return true;