zend-form

How to pass options/params to formCollection fieldset in ZendFramework 2?

北慕城南 提交于 2019-12-10 21:17:03
问题 I have a Form which contains a formCollection with a select element that I want to populate with values (from SQL) depending on a POST param. Passing this param from controller to form wasn't a problem but now I can't find a way to set/read that param in target_element of formCollection. Any ideas on how make that work? Here's my code: Controller class MyController extends AbstractActionController{ public function indexAction() { $form = $this->serviceLocator->get('FormElementManager')->get(

Date validator that validates if the date is greater than or equal to today with Zend Framework

天大地大妈咪最大 提交于 2019-12-10 16:36:45
问题 $form = new Zend_Form(); $mockDate = new Zend_Form_Element_Text('mock'); $mockDate->addValidator(???????); $form->addElements(array($mockDate)); $result = $form->isValid(); if ($result) echo "YES!!!"; else echo "NO!!!"; Assumption that the element is in a date format. How do I determine that the date given is greater than or equal to today? 回答1: You can create a simple validator to do this: class My_Validate_DateGreaterThanToday extends Zend_Validate_Abstract { const DATE_INVALID =

How can I set the order of Zend Form Elements and avoid duplicates

≯℡__Kan透↙ 提交于 2019-12-10 15:48:40
问题 In Zend Form, if two elements have the same order, then Zend will totally ignores the second element (instead of displaying it under the first). Take the following code as an example. Notice that the City and Zip Code elements have the same order of 4 $address = new Zend_Form_Element_Textarea('address'); $address->setLabel('Address') ->setAttrib('cols', 20) ->setAttrib('rows', 2) ->setOrder(3) ; $city = new Zend_Form_Element_Text('city'); $city->setLabel('City') ->setOrder(4) ; $postal = new

Requires a check box array using Zend_Form_Element_Checkbox

一笑奈何 提交于 2019-12-10 15:16:41
问题 I need an array of check-box that should look like as following: <input type="checkbox" name="myname[]" > Currently I am using new Zend_Form_Element_Checkbox('myname[]'); but it doesn't show the array in html control. It draw this as <input type="checkbox" name="myname"> AnySolution? 回答1: <?php $myname = new Zend_Form_Element_Checkbox('myname'); $myname->setLabel('This is my label') ->setRequired(true) ->addMultiOptions(array('myname' => true)); 来源: https://stackoverflow.com/questions/4145198

What is the regular expression for International phone number validation in php or zend?

微笑、不失礼 提交于 2019-12-10 14:17:11
问题 I have a zend form where I have a phone number field and have to check for validator. I have decided to use regular expression for that. I searched google but the results I have is not working. Can anyone please provide me the regular expression. here is my code: $phone = new Zend_Form_Element_Text('phone'); $phone->setRequired(true); $phone->setLabel('Phone :') ->addFilter('StripTags') ->addValidator('NotEmpty', false, array('messages'=>'phone cannot be empty')) ->addFilter('StringTrim') -

Zend framework form Decorators

夙愿已清 提交于 2019-12-10 11:09:22
问题 i am trying to get the following layout using decorators: <form action="/index/login" method="post" id="login_form"> <div class="input_row"> <img src="/images/user_icon.png" class="login_icon" alt=""/> <label for="username" class="login_label">Username:</label> <input type="text" name="username" value="" id="username" class="login_input" /> </div> <div class="input_row"> <img src="/images/password_icon.png" class="login_icon" alt=""/> <label for="password" class="login_label">Password:</label

zend form validation

可紊 提交于 2019-12-10 09:37:08
问题 I wonder how Zend_Form validates inputs, I mean how does it know which input fields to validate. I looked to php globals($_POST, $_GET) and I didn't see anything set as an identifier(for example ) in order to know how validate. Can anyone suggest me any guide for this stuff? 回答1: Well, the best option to find out is to look at the code of Zend_Form: /** * Validate the form * * @param array $data * @return boolean */ public function isValid($data) { if (!is_array($data)) { require_once 'Zend

Pass variable into Zend Form

别等时光非礼了梦想. 提交于 2019-12-10 09:34:07
问题 I have a zend form instantiated $form = Form_Example(); Now I want to pass an ID from my controller to my form. So I did this: $form = Form_Example(array('id' => $id)); Inside the form I try to call it through: $this->id But it isn't there. Anybody knows how to get that id into the form? Thanks 回答1: Make sure you have setter for the the element, in your case public function setId($id) . Zend_Form constructor checks if setter method exists for the property, if it exists then it is called,

How to set the message of the NotEmpty validator on a Zend_Form_Element?

前提是你 提交于 2019-12-10 09:26:41
问题 I have a form element that I'm setting as required: $this->addElement('text', 'email', array( 'label' => 'Email address:', 'required' => true )); Since I'm setting required to true, it makes sure that it's not empty. The default error message looks like this: "Value is required and can't be empty" I tried setting the message on the validator, but this throws a fatal error: $validator = $this->getElement('email')->getValidator('NotEmpty'); $validator->setMessage('Please enter your email

Add caching to Zend\Form\Annotation\AnnotationBuilder

可紊 提交于 2019-12-10 06:49:51
问题 As I've finally found a binary of memcache for PHP 5.4.4 on Windows, I'm speeding up the application I'm currently developing. I've succeeded setting memcache as Doctrine ORM Mapping Cache driver, but I need to fix another leakage: Forms built using annotations. I'm creating forms according to the Annotations section of the docs. Unfortunately, this takes a lot of time, especially when creating multiple forms for a single page. Is it possible to add caching to this process? I've browsed