zend-form

Is there a way to prefix Zend_Form element name?

前提是你 提交于 2019-12-12 16:14:57
问题 I have a page that has multiple forms on it. Several of the forms share an element with the same name like CustomerID. This means the element ID CustomerID will collide with that same ID in the other forms. I would like to find a clean way to prefix the field name with the name of the form. For instance PaymentProfile_CustomerID. Suggestions? So far, the best I have been able to come up with is: class MyForm extends Zend_Form { public function init() { $this->setName("PaymentProfile"); ...

ZF2 Form Hydration with multiple objects and fieldsets

蹲街弑〆低调 提交于 2019-12-12 15:33:11
问题 I'm struggling trying to work out how to edit multiple models with a single form. I have a database table called Teams and a doctrine entity associated with this table. I create a form as below: My team fieldset: class TeamFieldset extends AbstractFieldset implements InputFilterProviderInterface { public function init() { $this->setName('Team') ->setHydrator(new DoctrineHydrator($this->getObjectManager(),'Application\Model\Entities\Team')) ->setObject(new Team()) ->setLabel('Team'); $this-

zf2 form: populate select field with data coming from database

最后都变了- 提交于 2019-12-12 13:55:32
问题 I'm learning zf2 and I'm facing a problem involving 2 (eventually more) modules working together. Note, I've carefully read this post (and the related one) which helped me a lot. I'm going to explain a bit the problem: Using the first module (FrOption) an administrator can manage website form options. All options are stored in a db table like this: id|field_name|field_value 1|country|germany| 2|country|france| 3|gender|Male| 4|gender|Female| 5|tipo|Car| 6|tipo|Fly| ... In my module (FrItem) I

ZF2 Fieldsets and Form Binding

不想你离开。 提交于 2019-12-12 13:34:44
问题 I'm trying to create one page with a Form with two fieldsets that should each populate a different table. I can easily create One form as in the Album tutorial, and bind the data like this: $pageForm = new PageForm(); $pageForm->bind($page); with my PageForm class as follows: class PageForm extends Form { public function __construct($name = null) { // we want to ignore the name passed parent::__construct('page'); $this->setAttribute('method', 'post'); $this->add(array( 'name' => 'id',

Zend Framework 2 - Annotation form, RegEx validation and custom error messages

旧时模样 提交于 2019-12-12 10:12:18
问题 As outlined here I'm working with GeoPositionFields . Because this is not supported from Zend, I went with a standard RegEx validator. It works great but I still need a custom error message - any ideas how to achieve this? The one in my example just does nothing... /** * @ORM\Column(type="string") * @Form\Filter({"name":"StringTrim"}) * @Form\Validator({"name":"Regex", "options":{"pattern":"/(-?\d{1,3}\D\d+)[^\d-]+(-?\d{1,3}\D\d+)/"}}) * @Form\ErrorMessage("My custom message") * @Form

View Helper, Partial View or Something Else

给你一囗甜甜゛ 提交于 2019-12-12 09:53:39
问题 I am new to Zend Framework and I have a question about something I am trying to do. The main content of most pages of the application that I am working on will consist of 1 or more div elements that need to be styled the same. Here is an example of the HTML that I want to generate: <div id='admin-locations' class='panel'> <header class="panel-header"> <h2>Locations</h2> </header> <div class='panel-content'> <div id='locations-table' class='google-vis-table'></div> <form id='locations'> ... <

Zend_Validate_Db_RecordExists with Doctrine 2?

China☆狼群 提交于 2019-12-12 09:42:35
问题 I'm using Doctrine 2 in a Zend Framework application and require functionality similar to Zend_Validate_Db_RecordExists and Zend_Validate_Db_NoRecordExists. For example, when a user enters a new item, I need to validate that a duplicate entry doesn't already exist. This is easy to accomplish with Zend_Db by adding the Db_NoRecordExists validator on my forms. I tried implementing the custom-validator solution proposed here, but I can't figure out how they are communicating with Doctrine to

How to have a decorator applied as a default for all forms in Zend_Form?

六眼飞鱼酱① 提交于 2019-12-12 09:27:51
问题 I need to display form-level errors in my forms (errors that do not belong to one field, but to the whole form submission), with this code: $form->addError($message); For this to work, I need to add the relevant decorator to my form: $form->addDecorator('Errors'); Fairly easy. The problem is that applying a new decorator causes all default decorators to be removed, thus forcing me to re-apply all of them: $form->addDecorator('Errors') ->addDecorator('FormElements') ->addDecorator('HtmlTag',

Zend Validation Db_NoRecordExists and exclude option

自古美人都是妖i 提交于 2019-12-12 08:44:13
问题 I'm trying to use the "exclude" option for a Db_NoRecordExists validator, cause when I'm "editing" the element it always return me back a "duplicated" error, as usual. What I aim to is to tell to the form to keep back the value passed to the form itself from the Controller... This is the Controller: public function editAction() { $id = $this->getRequest()->getParam('id'); $pagesMapper = new Application_Model_PagesMapper(); $form = new Application_Form_PageEdit(); $form->populate($pagesMapper-

How do you Unit Test a Zend_Form that includes the CSRF form element?

余生长醉 提交于 2019-12-12 08:09:34
问题 I'm using the CSRF hidden hash element with Zend_Form and trying to Unit Test the login but don't know how to write a Unit Test to include that element. Looked in the docs and read as many tutorials as I could find. I even delicioused them all, but no one mentions this. 回答1: The correct hash is stored in the session, and the Hash form element has a Zend_Session_Namespace instance which contains the namespace for the hash. To unit test the element, you would replace the Zend_Session_Namespace