Re: [fw-general] Zend_Form textarea quoting issue
- Mensaje original - I have a form that only has one textarea and one submit button (no filters and no validators). So far I haven't added any functionality to it but as I was trying it I noticed that quotes get added incrementally with every submit on the rendered textarea's content. If I enter a single quote, the first time I submit it I get \', the second time I get \\\', so on and so forth... Am I doing something wrong here? Thanks, Julian. // Controller... $form = new TestingForm(); $request = $this-getRequest(); if ($request-isPost()) { $form-setData($request-getPost()); } return array( 'form' = $form, ); // index.phtml ?php $form = $this-form; $form-setAttribute('action', $this-url('home')); $form-prepare(); ? ?= $this-form()-openTag($form); ? ?= $this-formRow($form-get('text')); ? br/ ?= $this-formSubmit($form-get('submit')); ? br/ ?= $this-form()-closeTag(); ? Hi Julian, Check your PHP magic quotes configuration, it must be disabled. http://php.net/manual/en/security.magicquotes.disabling.php -- Alayn Gortazar -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
Re: [fw-general] Zend_Form textarea quoting issue
Hi, Alayn, Yep, they're off. :( On Mon, Nov 19, 2012 at 5:09 AM, Alayn Gortazar al...@irontec.com wrote: - Mensaje original - I have a form that only has one textarea and one submit button (no filters and no validators). So far I haven't added any functionality to it but as I was trying it I noticed that quotes get added incrementally with every submit on the rendered textarea's content. If I enter a single quote, the first time I submit it I get \', the second time I get \\\', so on and so forth... Am I doing something wrong here? Thanks, Julian. // Controller... $form = new TestingForm(); $request = $this-getRequest(); if ($request-isPost()) { $form-setData($request-getPost()); } return array( 'form' = $form, ); // index.phtml ?php $form = $this-form; $form-setAttribute('action', $this-url('home')); $form-prepare(); ? ?= $this-form()-openTag($form); ? ?= $this-formRow($form-get('text')); ? br/ ?= $this-formSubmit($form-get('submit')); ? br/ ?= $this-form()-closeTag(); ? Hi Julian, Check your PHP magic quotes configuration, it must be disabled. http://php.net/manual/en/security.magicquotes.disabling.php -- Alayn Gortazar
[fw-general] Zend_Form textarea quoting issue
I have a form that only has one textarea and one submit button (no filters and no validators). So far I haven't added any functionality to it but as I was trying it I noticed that quotes get added incrementally with every submit on the rendered textarea's content. If I enter a single quote, the first time I submit it I get \', the second time I get \\\', so on and so forth... Am I doing something wrong here? Thanks, Julian. // Controller... $form = new TestingForm(); $request = $this-getRequest(); if ($request-isPost()) { $form-setData($request-getPost()); } return array( 'form' = $form, ); // index.phtml ?php $form = $this-form; $form-setAttribute('action', $this-url('home')); $form-prepare(); ? ?= $this-form()-openTag($form); ? ?= $this-formRow($form-get('text')); ? br/ ?= $this-formSubmit($form-get('submit')); ? br/ ?= $this-form()-closeTag(); ?
[fw-general] Zend_Form + subforms and setBelongsTo(x)
Hello, I'm having a problem with Zend_Form trying to set up a group of Text boxs + combo box I whant to set a group like Service[0] [typeofservice] = XXX; Service[0] [numberofservice] = XXX; Service[0] [typeofservice2] = XXX; Service[0] [numberofservice2] = XXX; Service[1] [typeofservice] = XXX; Service[1] [numberofservice] = XXX; Service[1] [typeofservice2] = XXX; Service[1] [numberofservice2] = XXX; Doing a var_dump($_POST['servico'] I can see the values, but using var_dump($form-getValues()) the boxs appear filled with the number 3. Any sugestions to this issue or problem will be helpfull. Also if anyone can provide an example of the correct way of doing this with Zend_Form I'll be gratefull. Thank you in advance, FR Code bellow: public function servico() { $form = new Zend_Form_SubForm(); $form-setAttribs(array( 'name' = 'servicos', 'legend' = 'Serviços' ) ); $form-setDecorators(array( 'FormElements', array('HtmlTag', array('tag' = 'ul')), 'Form', )); for ($i = 0; $i 4; $i++) { $form-addSubForm($this-verServico($i), servico . $i); } return $form; } public function verServico($i) { $sub = new Zend_Form_SubForm(); $sub-clearDecorators(); $sub-setAttribs(array( 'name' = 'textboxtab' . $i, 'legend' = 'Serviço ' . ($i + 1) ) ); $sub-setIsArray(false); $sub-setDecorators(array( 'FormElements', array('HtmlTag', array('tag' = 'li')), 'Form', )); $sub-clearAttribs(); $net = new Zend_Form_Element_Select(serviconet . $i); $net-setLabel('Serviço ' . ($i + 1) . Internet) -setMultiOptions($this-servicosNet) //-setValue($this-getdata(serviconet)) -setOptions(array( onChange = formclienteComboNet(' . serviconet . $i . '); ) ) -setBelongsTo(serviconet . $i); $sub-addElement($net); $netmac = new Zend_Form_Element_Text(macaddr . $i); $netmac-setBelongsTo(serviconet . $i); $netmac-setLabel(Modem Mac Address (HFC MAC)); $sub-addElement($netmac); // Telefone $tel = new Zend_Form_Element_Select(servicotela . $i); $tel-setLabel(Telefone) -setBelongsTo(serviconet . $i) -setMultiOptions($this-servicosTelef) //-setValue($this-getdata(servicotelef)) -setOptions(array( onChange = formclienteComboTel(' . servicotela . $i . '); ) ) -setRegisterInArrayValidator(false); $sub-addElement($tel); $telnum = new Zend_Form_Element_Text(tel . $i); $telnum-setBelongsTo(serviconet . $i); $telnum-setLabel(Número); $sub-addElement($telnum); $sub-setElementDecorators(array( 'ViewHelper', 'Label', 'Errors', new Zend_Form_Decorator_HtmlTag(array('tag' = 'span')) //wrap elements in li's ), array(macaddr . $i, tel . $i, servicotela . $i, serviconet . $i ) ); $netmac-addDecorator( array('row' = 'HtmlTag'), array('tag' = 'div') ); $row = $netmac-getDecorator(row); $row-setOption(style, display: none;) -setOption(id, divmemac . serviconet . $i) ; $telnum-addDecorator( array('row' = 'HtmlTag'), array('tag' = 'div') ); $row = $telnum-getDecorator(row); $row-setOption(style, display: none;) -setOption(id, divme . servicotela . $i) ; return $sub; } -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-subforms-and-setBelongsTo-x-tp4105411p4105411.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
Re: [fw-general] Zend_Form and getValidValues
I don't think getValidValues() is the right method for your needs. When you call isValid($data) on a form, the form elements are populated and validated. getValidValues() is expecting a parameter of $data as well, but in looking through the code it looks like it passes on values that don't exist in the form. So, instead you should just call getValues() on the form. This will return only the values for form elements that exist in the form. Konr On Thu, Sep 15, 2011 at 4:50 PM, Sergio Rinaudo kaiohken1...@hotmail.com wrote: Hello Everyone, I am a bit confused with the getValidValues method of Zend_Form. I am using ZF 1.11.10. I'll explain my problem: I'm trying to get all the valid values of the $data array. $isValid = $form-isValid( $data ); if( $isValid ) { $validValues = $form-getValidValues(); Zend_Debug::dump( $validValues, 'validValues' ); exit; } else { Zend_Debug::dump( $form-getErrors() ); exit; } If $data contains keys that are not form elements, $validValues will contains them. Is that the correct behaviour of this method? The result I would is an array of data that is valid and is present as a form element, discarding what is not present, is there any way to accomplish this using Zend Form methods or maybe am I mistaking something? Thanks Sergio -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
RE: [fw-general] Zend_Form and getValidValues
Hi Konr , yes, you're right, I was mistaking in another part of my code and also not to pass tha required argument, I've found it a few minutes after I opened this post and replied to my own question, but I see the message This post has NOT been accepted by the mailing list yet. so maybe you cannot see it. However, thank you for your answer, is always good to have some good advice from a friend! Regards Sergio Rinaudo Date: Mon, 19 Sep 2011 14:11:14 -0500 Subject: Re: [fw-general] Zend_Form and getValidValues From: konrn...@gmail.com To: kaiohken1...@hotmail.com CC: fw-general@lists.zend.com I don't think getValidValues() is the right method for your needs. When you call isValid($data) on a form, the form elements are populated and validated. getValidValues() is expecting a parameter of $data as well, but in looking through the code it looks like it passes on values that don't exist in the form. So, instead you should just call getValues() on the form. This will return only the values for form elements that exist in the form. Konr On Thu, Sep 15, 2011 at 4:50 PM, Sergio Rinaudo kaiohken1...@hotmail.com wrote: Hello Everyone, I am a bit confused with the getValidValues method of Zend_Form. I am using ZF 1.11.10. I'll explain my problem: I'm trying to get all the valid values of the $data array. $isValid = $form-isValid( $data ); if( $isValid ) { $validValues = $form-getValidValues(); Zend_Debug::dump( $validValues, 'validValues' ); exit; } else { Zend_Debug::dump( $form-getErrors() ); exit; } If $data contains keys that are not form elements, $validValues will contains them. Is that the correct behaviour of this method? The result I would is an array of data that is valid and is present as a form element, discarding what is not present, is there any way to accomplish this using Zend Form methods or maybe am I mistaking something? Thanks Sergio
[fw-general] Zend_Form and getValidValues
Hello Everyone, I am a bit confused with the getValidValues method of Zend_Form. I am using ZF 1.11.10. I'll explain my problem: I'm trying to get all the valid values of the $data array. $isValid = $form-isValid( $data ); if( $isValid ) { $validValues = $form-getValidValues(); Zend_Debug::dump( $validValues, 'validValues' ); exit; } else { Zend_Debug::dump( $form-getErrors() ); exit; } If $data contains keys that are not form elements, $validValues will contains them. Is that the correct behaviour of this method? The result I would is an array of data that is valid and is present as a form element, discarding what is not present, is there any way to accomplish this using Zend Form methods or maybe am I mistaking something? Thanks Sergio
Re: [fw-general] Zend_Form: adding css class attrib to select option elements
On Sat 23 Jul 2011 04:27:16 AM EST, Bart McLeod wrote: Op 22-07-11 17:06, David Mintz schreef: On Thu, Jul 21, 2011 at 5:19 PM, Bart McLeodmcl...@spaceweb.nl wrote: My wild guess is that you should override addMultiOptions in a custom select element so that you can add the class attribs. -Bart Op 21-07-11 21:49, David Mintz schreef: From my googling I see that this has been asked, and there's no really easy answer, and none of the few answers I found work for my case. Basically, you have a label, a value and a category signified by the css class. I want the output to be something like option label=apple class=fruit value=1apple/option option label=spinach class=vegetable value=wspinach/option option label=salmon class=fish value=1salmon/option And yes, I know there are option groups for organizing OPTION elements into a hierarchy, but I have my reasons for not wanting to go there. This will all come from a database. In high-level terms, how would you suggest approaching this? What classes/methods would you look into overriding? The purpose is to do fancy tricks using jQuery -- I need to detect the category on the change event. I can think of ways of hacking around this, e.g., load a JSON data structure that maps ids to categories and refer to that as needed. But... any other ideas? Thanks Bart. I noticed that $helper is a public property of Zend_Form_Element_Select, so rather than extending it, I have started working on a custom view helper instead, whose method signature is the same as that of formSelect in Zend_View_Helper_FormSelect. But the $options array that I am going to pass the Zend_Form_Element_Select constructor won't be like array( 1= apple, 2 = spinach ), but rather array( array(value=1,label=spinach, class=vegetable ), ... ) Any thoughts about this approach? I know that it's kind of crude to deliberately abuse Zend_Form_Element_Select's constructor and then give it a custom view helper to make up for it, but it looks like it's gonna work. Indeed it sounds like it's going to work and I do not see the crude aspect. If the constructor can be used this way it is the strength of the architecture that makes this possible. I looked at the issue in the tracker and that doesn't sound bad either, although I wonder how it would perform with a lot of options. I had a similar issue where I wanted to include a title attribute for each option. Ended up just going the manual rendering route as it gave me a lot more control, and as a bonus, doesn't require the gymnastics needed to get an array that works with formSelect. David -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
[fw-general] Zend_Form: adding css class attrib to select option elements
On Thu, Jul 21, 2011 at 5:19 PM, Bart McLeod mcl...@spaceweb.nl wrote: My wild guess is that you should override addMultiOptions in a custom select element so that you can add the class attribs. -Bart Op 21-07-11 21:49, David Mintz schreef: From my googling I see that this has been asked, and there's no really easy answer, and none of the few answers I found work for my case. Basically, you have a label, a value and a category signified by the css class. I want the output to be something like option label=apple class=fruit value=1apple/option option label=spinach class=vegetable value=wspinach/option option label=salmon class=fish value=1salmon/option And yes, I know there are option groups for organizing OPTION elements into a hierarchy, but I have my reasons for not wanting to go there. This will all come from a database. In high-level terms, how would you suggest approaching this? What classes/methods would you look into overriding? The purpose is to do fancy tricks using jQuery -- I need to detect the category on the change event. I can think of ways of hacking around this, e.g., load a JSON data structure that maps ids to categories and refer to that as needed. But... any other ideas? Thanks Bart. I noticed that $helper is a public property of Zend_Form_Element_Select, so rather than extending it, I have started working on a custom view helper instead, whose method signature is the same as that of formSelect in Zend_View_Helper_FormSelect. But the $options array that I am going to pass the Zend_Form_Element_Select constructor won't be like array( 1= apple, 2 = spinach ), but rather array( array(value=1,label=spinach, class=vegetable ), ... ) Any thoughts about this approach? I know that it's kind of crude to deliberately abuse Zend_Form_Element_Select's constructor and then give it a custom view helper to make up for it, but it looks like it's gonna work. -- David Mintz http://davidmintz.org/ It ain't over: http://www.healthcare-now.org/
Re: [fw-general] Zend_Form: adding css class attrib to select option elements
Am 22.07.2011, 17:06 Uhr, schrieb David Mintz da...@davidmintz.org: I noticed that $helper is a public property of Zend_Form_Element_Select, so rather than extending it, I have started working on a custom view helper instead, whose method signature is the same as that of formSelect in Zend_View_Helper_FormSelect. But the $options array that I am going to pass the Zend_Form_Element_Select constructor won't be like array( 1= apple, 2 = spinach ), but rather array( array(value=1,label=spinach, class=vegetable ), ... ) Any thoughts about this approach? I know that it's kind of crude to deliberately abuse Zend_Form_Element_Select's constructor and then give it a custom view helper to make up for it, but it looks like it's gonna work. Use CSS: option[label='Foo'] { background-color: red; } option[label='Bar'] { background-color: yellow; } Or look at the issue tracker: http://framework.zend.com/issues/browse/ZF-3580 -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
Re: [fw-general] Zend_Form: adding css class attrib to select option elements
On Fri, Jul 22, 2011 at 11:22 AM, Kaiuwe dr.kai...@googlemail.com wrote: Am 22.07.2011, 17:06 Uhr, schrieb David Mintz da...@davidmintz.org: I noticed that $helper is a public property of Zend_Form_Element_Select, so rather than extending it, I have started working on a custom view helper instead, whose method signature is the same as that of formSelect in Zend_View_Helper_FormSelect. But the $options array that I am going to pass the Zend_Form_Element_Select constructor won't be like array( 1= apple, 2 = spinach ), but rather array( array(value=1,label=spinach, class=vegetable ), ... ) Any thoughts about this approach? I know that it's kind of crude to deliberately abuse Zend_Form_Element_Select's constructor and then give it a custom view helper to make up for it, but it looks like it's gonna work. Use CSS: option[label='Foo'] { background-color: red; } option[label='Bar'] { background-color: yellow; } Or look at the issue tracker: http://framework.zend.com/** issues/browse/ZF-3580 http://framework.zend.com/issues/browse/ZF-3580 Actually I'm not concerned about CSS presentation at all. The 'class' attribute would be strictly semantic, and make it easier to know how to handle certain 'change' events with jQuery. The proposal in the issue tracker, if I understand it correctly, presumes you want all your options to have the same class -- which is less than trivial to do in js. In my case... well I already explained it earlier. -- David Mintz http://davidmintz.org/ It ain't over: http://www.healthcare-now.org/
Re: [fw-general] Zend_Form: adding css class attrib to select option elements
Am 22.07.2011, 17:43 Uhr, schrieb David Mintz da...@davidmintz.org The proposal in the issue tracker, if I understand it correctly, presumes you want all your options to have the same class… Sorry, wrong! It is for one option element. There is a difference between: addMultiOption and addMultiOptions. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
Re: [fw-general] Zend_Form: adding css class attrib to select option elements
Op 22-07-11 17:06, David Mintz schreef: On Thu, Jul 21, 2011 at 5:19 PM, Bart McLeodmcl...@spaceweb.nl wrote: My wild guess is that you should override addMultiOptions in a custom select element so that you can add the class attribs. -Bart Op 21-07-11 21:49, David Mintz schreef: From my googling I see that this has been asked, and there's no really easy answer, and none of the few answers I found work for my case. Basically, you have a label, a value and a category signified by the css class. I want the output to be something like option label=apple class=fruit value=1apple/option option label=spinach class=vegetable value=wspinach/option option label=salmon class=fish value=1salmon/option And yes, I know there are option groups for organizing OPTION elements into a hierarchy, but I have my reasons for not wanting to go there. This will all come from a database. In high-level terms, how would you suggest approaching this? What classes/methods would you look into overriding? The purpose is to do fancy tricks using jQuery -- I need to detect the category on the change event. I can think of ways of hacking around this, e.g., load a JSON data structure that maps ids to categories and refer to that as needed. But... any other ideas? Thanks Bart. I noticed that $helper is a public property of Zend_Form_Element_Select, so rather than extending it, I have started working on a custom view helper instead, whose method signature is the same as that of formSelect in Zend_View_Helper_FormSelect. But the $options array that I am going to pass the Zend_Form_Element_Select constructor won't be like array( 1= apple, 2 = spinach ), but rather array( array(value=1,label=spinach, class=vegetable ), ... ) Any thoughts about this approach? I know that it's kind of crude to deliberately abuse Zend_Form_Element_Select's constructor and then give it a custom view helper to make up for it, but it looks like it's gonna work. Indeed it sounds like it's going to work and I do not see the crude aspect. If the constructor can be used this way it is the strength of the architecture that makes this possible. I looked at the issue in the tracker and that doesn't sound bad either, although I wonder how it would perform with a lot of options. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
[fw-general] Zend_Form: adding css class attrib to select option elements
From my googling I see that this has been asked, and there's no really easy answer, and none of the few answers I found work for my case. Basically, you have a label, a value and a category signified by the css class. I want the output to be something like option label=apple class=fruit value=1apple/option option label=spinach class=vegetable value=wspinach/option option label=salmon class=fish value=1salmon/option And yes, I know there are option groups for organizing OPTION elements into a hierarchy, but I have my reasons for not wanting to go there. This will all come from a database. In high-level terms, how would you suggest approaching this? What classes/methods would you look into overriding? The purpose is to do fancy tricks using jQuery -- I need to detect the category on the change event. I can think of ways of hacking around this, e.g., load a JSON data structure that maps ids to categories and refer to that as needed. But... any other ideas? Thanks. -- David Mintz http://davidmintz.org/ It ain't over: http://www.healthcare-now.org/
Re: [fw-general] Zend_Form: adding css class attrib to select option elements
My wild guess is that you should override addMultiOptions in a custom select element so that you can add the class attribs. -Bart Op 21-07-11 21:49, David Mintz schreef: From my googling I see that this has been asked, and there's no really easy answer, and none of the few answers I found work for my case. Basically, you have a label, a value and a category signified by the css class. I want the output to be something like option label=apple class=fruit value=1apple/option option label=spinach class=vegetable value=wspinach/option option label=salmon class=fish value=1salmon/option And yes, I know there are option groups for organizing OPTION elements into a hierarchy, but I have my reasons for not wanting to go there. This will all come from a database. In high-level terms, how would you suggest approaching this? What classes/methods would you look into overriding? The purpose is to do fancy tricks using jQuery -- I need to detect the category on the change event. I can think of ways of hacking around this, e.g., load a JSON data structure that maps ids to categories and refer to that as needed. But... any other ideas? Thanks. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
[fw-general] Zend_Form-errors: inconsistent behavior
Hi, I noticed that the result returned by Zend_Form-getErrors() can not be used as argument for Zend_Form-addErrors(), as the array-formats do not match: getErrors() array(__ELEMENT_NAME__ = array(__ERROR_MESSAGE__)); addErrors() array(__ERROR_MESSAGE__); How could I go about having addErrors changed, so it will take both formats? Should I create a new issue (improvement)? If necessary, I will commit a patch myself, but I haven't signed a CLA yet and don't want to meddle around in Zend_Form if someone else feels responsible... Regards, Denis Brumann -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
Re: [fw-general] Zend_Form, shifting validation off the element onto the form object..
-- leedavis leedavi...@gmail.com wrote (on Friday, 08 April 2011, 07:15 AM -0700): The thing I cant get my head around, is, if forms can be in an error state using methods such as setError(s), addErrorMessage(s) etc. Then why cant we attach validators to a form object? Why are these limited to form elements only? It could be that I'm completely missing something or simply not using Zend_Form as intended. But we have an error messages stack and status encapsulated within the form object, why cant we attach validators directly that will manipulate this, exactly how you would to a form element? There's several reasons. First, in order to have re-usable elements, and in order to allow chains of validators per-element, validators must be attached per-element, and must be stateful per-element. For example, if I have a Between validator, I may have different min/max ranges per-element. Second, because of the above decision, at first, Zend_Form was simply validating elements and returning the aggregate; if any individual element failed validation, the form did as well, plain and simple. The ability to mark a form as invalid and attach errors and messages was added later as developers indicated these features would be useful. Nobody has yet requested a form-level validator -- except in the context of having a validator chain that could be shared between a domain entity and the form object. However, this is fairly contrary to the original design decision outlined above, and we feel it would require a fair amount of architectural change to accomplish. As such, we're taking that idea in mind for refactoring for ZF2 -- but not before. wouldn't it be nicer if I could just add validators directly to my form, such as.. class App_Form_Payment extends Zend_Form { public function __construct () { $this-addValidator(new App_Form_Validators_SinglePayment()); } } Thoughts? -- Matthew Weier O'Phinney Project Lead| matt...@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
[fw-general] Zend_Form, shifting validation off the element onto the form object..
Validating your data from a zend form object. In most cases validation would typically be attributed directly to the form element in question, for example validating an email address may use the EmailAddress validator shipped with ZF or you may want to create your own to ensure the email address isn't already registered, requiring a little more than a simple syntax check. However, I need to append a validator to a form itself. I have a small form which allows you to add payment requests to an account, and this account can only ever have one pending payment at any one time. My validator will check for pending payments on the account, if any exist invalidate the form and produce a message to say pending payments are already outstanding. This isn't specific to any element within the form, and anywhere this form is used within my application I want this validation check to be run, and error produced upon failure. So encapsulating it within the form object I feel is the correct place to put it. I've achieved exactly what I need by doing the following: * extending the form's isValid() method * adding the FormErrors decorator, so the error is spewed out * injecting any fail messages from my validator into the form object using addErrors($message) * continuing with parent::isValid if my validator passes Here is an example.. class App_Form_Payment extends Zend_Form { .. (construction stuff) public function isValid( $value ) { // add in a additional validator $paymentVal = new App_Form_Validators_SinglePayment(); if (!$paymentVal-isValid($this-getPackageId())) { $this-addErrors($paymentVal-getMessages()); return false; } return parent::isValid( $value ); } } Adding custom errors to the form object is very easy and useful, you can even flag the form as encountered an error without having to parse any message information at all using the markAsError() method. The thing I cant get my head around, is, if forms can be in an error state using methods such as setError(s), addErrorMessage(s) etc. Then why cant we attach validators to a form object? Why are these limited to form elements only? It could be that I'm completely missing something or simply not using Zend_Form as intended. But we have an error messages stack and status encapsulated within the form object, why cant we attach validators directly that will manipulate this, exactly how you would to a form element? wouldn't it be nicer if I could just add validators directly to my form, such as.. class App_Form_Payment extends Zend_Form { public function __construct () { $this-addValidator(new App_Form_Validators_SinglePayment()); } } Thoughts? Lee Davis -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-shifting-validation-off-the-element-onto-the-form-object-tp3436410p3436410.html Sent from the Zend Framework mailing list archive at Nabble.com. -- List: fw-general@lists.zend.com Info: http://framework.zend.com/archives Unsubscribe: fw-general-unsubscr...@lists.zend.com
[fw-general] Zend_Form Radio-Button Decorator
Hi! Sorry for my non-perfect english ^^ After creating an own browser-game with php (without Zend) I am now trying to learn Zend ... This time I am developing a web-community with some people. For this we use the Zend-Framework. All I didn't knew yet I was able to let google and documentations help me - without any problems furthermore. But I can search for hours - for this problem I can't find a solution at all! I have to use html-code in Label's. So I use this Code for Label-Decorator's: public static function getHtmlLabelDecorator() { return array( 'ViewHelper', array('Label', array('escape' = false)) ); } and it works great with most element-type's. But with Radio-Buttons it generates this sort of Code-Output: dt id=profilfoto-labellabel class=optionallt;br/gt;lt;br/gt;lt;h1gt;Dinge, die du denkstlt;/h1gt;lt;br/gt;Ist es dir wichtig, dass dein Gegen?ber ein Foto von sich im Profil hat?lt;br/gt;/label/dt label for=profilfoto-1input type=radio name=profilfoto id=profilfoto-1 value=1 /Ja/labelbr /label for=profilfoto-2input type=radio name=profilfoto id=profilfoto-2 value=2 /Nein/label in the code it looks like this: $this-addElement('radio', 'profilfoto', array( 'id' = 'profilfoto', 'name' = 'profilfoto', 'label'= 'br/br/h1Dinge, die du denkst/h1br/Ist es dir wichtig, dass dein Gegen?ber ein Foto von sich im Profil hat?br/', 'Decorators' = HimmlischPlaudern_Util_Constants::getHtmlLabelDecorator(), 'required' = false, 'multiOptions' = HimmlischPlaudern_Util_Constants::getGenerelAnswerArray() )); With all other elements with which I use this decorator-function, it works really great - for example with textarea oder a simple text-input-field. Can anyone help me changing the function getHtmlLabelDecorator() in order to get the html-code-output dislayed correcty instead of constructions like gt like above?!? ... hoping to find help here! kind regards from germany, Dennis -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-Radio-Button-Decorator-tp3228366p3228366.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form and Custom Error Messages
Hello, What is the most straight-forward way to mark an element as invalid and display a custom error message *without using validators*? For example, we are using a web service to process data submitted via a web form. I have set up validators in my form for the basic things like required fields and string length, but sometimes there is additional validation that occurs on the web-service side that could prevent the process from continuing. In that event I'd like to take the error message from the web service and inject it into the offending form element to be displayed to the user. I've looked over the API and documentationhttp://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.validators.errorsand there are two methods that seem likely candidates for doing my bidding: *Zend_Form_Element#setErrors(array $errors)* *Overwrite any previously set error messages and flag as failed validation* *Zend_Form_Element#setErrorMessages(array $errorMessages)* *Same as addErrorMessages(), but clears custom error message stack first* If I use setErrors() and pass in an array with a single error message, the message is duplicated when rendering. If I use setErrorMessages() and pass in an array with a single error message, the message is not displayed at all when rendering. I found that if I call both methods and pass in the same single-value array to both of them, it works as expected -- I get my nice error message on the rendered form. Is this typically how it should be done? Or am I missing something? Thanks! -- *Hector Virgen* Sr. Web Developer http://www.virgentech.com
Re: [fw-general] Zend_Form, and Translation of Zend_Validator messages
Very nice, Thanks Christian. How can I participate to add my own languages (Persian, ir) to the resources? Kind regards, -behzad
[fw-general] Zend_Form, and Translation of Zend_Validator messages
Hi, The error-messages of Zend_Validator_*** classes are located in different files, making it difficult to localize them at once. Are you aware of any .po file, containing a list of error messages, to ease the l10n? Please let me know. Thank you in advance, -b
Re: [fw-general] Zend_Form, and Translation of Zend_Validator messages
Download the full package of the zend framework files. There is a folder called resources\languages and inside are folders for different languages. Inside those is each a Zend_Validate.php which contains all the strings of each validator and it's translation in those languages already, in the array format. Using that file, it should be a breeze to create a suitable file for you own needs. On Thu, Oct 28, 2010 at 8:56 PM, AmirBehzad Eslami behzad.esl...@gmail.com wrote: Hi, The error-messages of Zend_Validator_*** classes are located in different files, making it difficult to localize them at once. Are you aware of any .po file, containing a list of error messages, to ease the l10n? Please let me know. Thank you in advance, -b -- Greetings, Christian Riesen http://christianriesen.com/ - My personal page http://toreas.com/ - Toreas a free fantasy novel http://gamewiki.net/ - Open Videogames Wiki
Re: [fw-general] Zend_Form - Unable to translate error messages post-validation
Thanks for the clarification, Thomas. I'll be sure to add translations prior to validating. -- *Hector Virgen* Sr. Web Developer Walt Disney Parks and Resorts Online http://www.virgentech.com
AW: [fw-general] Zend_Form - Unable to translate error messages post-validation
Well, isValid adds the error message to the form as it recognises that the form or it's elements are not valid. When you add a translation after the error has been set, then how should it be translated? That's like sending a manual to your customer and then translating it after your customer received it. Your customer will never get the translated version except you send it to him. You can translate it afterwards by creating adding translation adapter and calling isValid once again. But that's a suboptimal solution :-) It's always better to attach translations to the form as you also want to show your customer a already translated form. Thomas Weidner Zend Framework Certified Engineer I18N Team Leader http://www.thomasweidner.com -Ursprüngliche Nachricht- Von: Hector Virgen [mailto:djvir...@gmail.com] Gesendet: Freitag, 22. Oktober 2010 19:02 An: Zend Framework General Betreff: [fw-general] Zend_Form - Unable to translate error messages post-validation Hello, I've been following Matthew Weier O'Phinney's blog post Using Zend_Form In Your Modelshttp://weierophinney.net/matthew/archives/200-Using-Zend_Form-in-Your -Models.htmland so far it has been working great -- except for translation. We are currently not using Zend_Translate -- our solution is to use a view helper to apply the translated labels, descriptions etc to the form just prior to rendering. But the problem I am experiencing also occurs when Zend_Translate is used. If I pass in a translation adapter to the form after calling Zend_Form#isValid(), everything gets translated except for the error messages. However, if I pass in the translation adapter *before* validating, everything works as expected. I've put together the following unit tests to confirm it: Unit tests: http://pastie.org/1241063 Result: http://pastie.org/1241069 It seems that the solution would be to update my form to apply the translation adapter in its init() method, but I've delegated that responsibility to the view script (similar to other view-related tasks in Matthew's blog). The main reason for that is due to our translations being stored in a CMS, which our model does not have access to (the model only contains business rules). Additionally, I'm not always rendering the form, so supplying a translation adapter when I only need to validate is a waste of resources. After some poking around through the source of Zend_Form_Element, there doesn't appear to be a way to directly modify the error messages. I ended up using ReflectionObject to manually modify Zend_Form_Element's protected $_messages array -- but this seems very hackish to me. Is there a better way? -- *Hector Virgen* Sr. Web Developer Walt Disney Parks and Resorts Online http://www.virgentech.com
[fw-general] Zend_Form - Unable to translate error messages post-validation
Hello, I've been following Matthew Weier O'Phinney's blog post Using Zend_Form In Your Modelshttp://weierophinney.net/matthew/archives/200-Using-Zend_Form-in-Your-Models.htmland so far it has been working great -- except for translation. We are currently not using Zend_Translate -- our solution is to use a view helper to apply the translated labels, descriptions etc to the form just prior to rendering. But the problem I am experiencing also occurs when Zend_Translate is used. If I pass in a translation adapter to the form after calling Zend_Form#isValid(), everything gets translated except for the error messages. However, if I pass in the translation adapter *before* validating, everything works as expected. I've put together the following unit tests to confirm it: Unit tests: http://pastie.org/1241063 Result: http://pastie.org/1241069 It seems that the solution would be to update my form to apply the translation adapter in its init() method, but I've delegated that responsibility to the view script (similar to other view-related tasks in Matthew's blog). The main reason for that is due to our translations being stored in a CMS, which our model does not have access to (the model only contains business rules). Additionally, I'm not always rendering the form, so supplying a translation adapter when I only need to validate is a waste of resources. After some poking around through the source of Zend_Form_Element, there doesn't appear to be a way to directly modify the error messages. I ended up using ReflectionObject to manually modify Zend_Form_Element's protected $_messages array -- but this seems very hackish to me. Is there a better way? -- *Hector Virgen* Sr. Web Developer Walt Disney Parks and Resorts Online http://www.virgentech.com
Re: [fw-general] Zend_Form has a problem with swedis h characters (å,ä and ö)
Hi Your problem lies in layout.phtml (application/layout/scripts) and there on line 4: meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 / The charset you have there does not work so well with mixed characters. My advice is, use UTF-8 instead: meta http-equiv=Content-Type content=text/html; charset=UTF-8 If you are going to use a database, also use UTF-8 in there and you should be fine all through the application. On Mon, Sep 6, 2010 at 7:21 AM, bananabreeze sperling_da...@hotmail.comwrote: Hi! Zend_Form has trouble working with swedish characters å,ä and ö. -Zend_Form_Element: Using setLabel(), labels containing these chars will be set to ! -The same will happen to the default data when applying Zend_Form()-populate($values) . This makes it very annoying to work with non English/American data (to say the least). Anyone else ran into this? ;) Now let's look at screenshot and provided sample code... Cheers /Dave [image: screenshot] ZendFormTestApplication.ziphttp://zend-framework-community.634137.n4.nabble.com/file/n2527917/ZendFormTestApplication.zip -- View this message in context: Zend_Form has a problem with swedish characters (å,ä and ö)http://zend-framework-community.634137.n4.nabble.com/Zend-Form-has-a-problem-with-swedish-characters-a-and-o-tp2527917p2527917.html Sent from the Zend Framework mailing list archivehttp://zend-framework-community.634137.n4.nabble.com/Zend-Framework-f634138.htmlat Nabble.com. -- Greetings, Christian Riesen http://christianriesen.com/ - My personal page http://toreas.com/ - Toreas a free fantasy novel http://gamewiki.net/ - Open Videogames Wiki
[fw-general] Zend_Form has a problem with swedish characters (å,ä and ö)
Hi! Zend_Form has trouble working with swedish characters å,ä and ö. -Zend_Form_Element: Using setLabel(), labels containing these chars will be set to ! -The same will happen to the default data when applying Zend_Form()-populate($values) . This makes it very annoying to work with non English/American data (to say the least). Anyone else ran into this? ;) Now let's look at screenshot and provided sample code... Cheers /Dave http://zend-framework-community.634137.n4.nabble.com/file/n2527917/screenshot.png http://zend-framework-community.634137.n4.nabble.com/file/n2527917/ZendFormTestApplication.zip ZendFormTestApplication.zip -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-has-a-problem-with-swedish-characters-a-and-o-tp2527917p2527917.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] [Zend_Form] Filtering or validating a composite element's array of values
I have a composite element (MultiCheckbox for pre-defined values + Text for custom values; all having the same name) that is having validation problems. The field is required (at the very least, one of the checkboxes must be checked *or* there must be a value in the text field). The problem is that text fields are always submitted and a NotEmpty validator will fail on an empty text field, even if one of the boxes is checked. Even a custom validator that uses the $context parameter is not ideal, as it will still be called for each and every value in the element's array. A similar problem with Zend_Filter_Input was worked around by hacking in a TRAVERSE_ARRAY boolean option, but that seems impossible to implement in Zend_Form without rebuilding the entire Zend_Form_Element_* family on top of a custom validator class. Does anyone have any thoughts on this? Thanks, Ryan
[fw-general] zend_form for dummies: force-feeding a datum to a form
Long story, but I would like to add a form element -- it might as well be ' hidden' -- set its value and manually mark it as valid before calling validate so that this element name/value will be in the $context that a validator requires. I would rather not render this element along with the rest of the form because it's basically none of the end user's business. if ($this-getRequest()-isPost()) { $personForm-person_type_id-setValue(1); -- Support real health care reform: http://phimg.org/ -- David Mintz http://davidmintz.org/
[fw-general] Zend_Form | Using file form elements in subforms
Hello there, I'm currently trying to setup a Form including a SubForm (as described in http://framework.zend.com/manual/en/zend.form.advanced.html) to achieve a form with following inputs: input type=file name=avatar[file] / input type=hidden name=avatar[id] / The id is the one of the avatar table in my database, I store the entry within the getValue method to return the id instead of the filename after moving (receiving) it. To achieve the proper html name attributes I already had to overwrite the file decorator (Zend_Form_Decorator_File) to use getFullyQualifiedName instead of getName(). Now, sadly, I do not get the validation properly set up, as the transfer adapter (Zend_File_Transfer_Adapter_Abstract) only gets the name instead of the fully qualified name or container name and I don't know whether providing the belongs_to value in favor of the name is the right way to go. Has anyone already built a similar form setup with Zend_Form yet or can help in some other way? Greets, Sven
[fw-general] Zend_Form elements validating
Hi, I'm very new in zend framework and web developing. I'm currently writing a zend_form for a registration page of a web site. Here is my code for adding a text element for email address: http://pastie.org/1060337 In this email field i want to put EmailAddress validator, however there are many types of validation failure and a variety of error messages. What i want to do is to set a single and only one message for any type of fail of validation. I tried setMessage(), setMessages etc functions and got no solution so i rewrote most of the possible error messages. My Zend Framework version is 1.10.2. If you know any better way to do this, i'm looking forward to your replies:) -- Sabri Şahin Can +90 506 225 79 97 sabrisahin...@gmail.com Boğaziçi University Computer Engineering Department Bebek / Istanbul 34342
Re: [fw-general] Zend_Form and custom validation workaround
Create subforms to take advantage of array notation and have the validator compare the pair by naming convention. - pw On Thu, Jul 1, 2010 at 10:00 AM, milesap mile...@gmail.com wrote: I have a problem that I cannot seem to wrap my head around. 3 text fields on my form are start dates, and another 3 text fields are end dates. I need to validate the end dates to their corresponding starting dates to ensure they are later than the start dates. I created a custom validator for this, but this won't work because the validator doesn't know which element called it, and therefore cannot use the $context variable to determine the start date. What can I do here apart from creating 3 of the same validators, one for each end date field? Sample form: Start date of Program = End Date of Program Early fee start date = Early fee end date Late fee start date = Late fee end date -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-and-custom-validation-workaround-tp2275449p2275449.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form and custom validation workaround
I have a problem that I cannot seem to wrap my head around. 3 text fields on my form are start dates, and another 3 text fields are end dates. I need to validate the end dates to their corresponding starting dates to ensure they are later than the start dates. I created a custom validator for this, but this won't work because the validator doesn't know which element called it, and therefore cannot use the $context variable to determine the start date. What can I do here apart from creating 3 of the same validators, one for each end date field? Sample form: Start date of Program = End Date of Program Early fee start date = Early fee end date Late fee start date = Late fee end date -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-and-custom-validation-workaround-tp2275449p2275449.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form isValidPartial always returns false
Hi All, I have a form sent automatically every X seconds using ajax to store temporarily in a session all valid element values, and I want to use $myForm-isValidPartial server side to do this. Unfortunatelly it always returns false, and I have elements that actually should pass validation within the not-validated elements. Instead, If I call $myForm-isValidPartial to upload an image ( always using ajax ) it returns true ( like it should be ). I have all validators disabled for each form element. Does anybody have any clue about this issue? Thanks! Sergio _ nome.cognome @... Verifica la disponibilità sui NUOVI domini https://signup.live.com/signup.aspx?mkt=it-itrollrs=12lic=1
[fw-general] Zend_Form Array Notation values being re-indexed
Hi, I have just upgraded to ZF 1.10.4 and this has caused a lot of problems with by array notation forms. I notice there have been a lot of changes but I can't find the answer to my problem! I used to add elements to sub forms for adjusting quantities, the name of the element would be the id of the item, thus creating forms like so: Textbox: quantity[717] Textbox: quantity[718] Textbox: quantity[900] etc. etc. However this morning after the upgrade this stopped working and all the data coming out of Zend_Form-getValues() has been re-indexed starting at 0. I noticed something about re-indexing in Jira but don't think it relates. The new values are: quantity[0] = quantity[1] = quantity[2] = Have I missed a new flag or is this now broken? Thanks Simon -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-Array-Notation-values-being-re-indexed-tp2122097p2122097.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form composite time element
I followed his tutorial to create my own date composite element, but I wanted to use selects instead of text fields. I added 3 new methods to the element that returns the multiOptions for each of the selects: My_Form_Element_Date#getMonthMultiOptions() My_Form_Element_Date#getDayMultiOptions() My_Form_Element_Date#getYearMultiOptions() I also add setters for each of those so I can specify what the options should be when creating the form. For example, sometimes I want years in the past (for date of birth) and sometimes I want years in the future (for scheduling events). When building the decorator, I then pulled the multiOptions from the element using those methods and used the formSelect() helper instead of formText(). You should be able to do the same thing to create your own time composite element. -- Hector On Sun, Apr 25, 2010 at 11:03 AM, Jigal sanders jigalroe...@gmail.comwrote: Hello everyone, I have been busy implementing my own custom time form element. And I asume that I am not doing anything which is rocket science. Namely I am trying to create a custom form element which I can use to enter times. It shoul look like two dropdown boxes of which i can select the hours and minutes.The seconds should be set default to 00 as they are not important. Now I have been trying various things and i have been pointend to Matthew Weier O'phinney's tutorial over here http://bit.ly/bswioH about creating composite form elements. I think he is doing over here exactly the same as I do, just i want to use different form element's. My question is how would I be able to use this very same example but in stead of using a date format I want to use it to set a time with the use of select boxes. I would appreciate it very much if someone can give me directions. Kind regards, J. Sanders
[fw-general] Zend_Form composite time element
Hello everyone, I have been busy implementing my own custom time form element. And I asume that I am not doing anything which is rocket science. Namely I am trying to create a custom form element which I can use to enter times. It shoul look like two dropdown boxes of which i can select the hours and minutes.The seconds should be set default to 00 as they are not important. Now I have been trying various things and i have been pointend to Matthew Weier O'phinney's tutorial over here http://bit.ly/bswioH about creating composite form elements. I think he is doing over here exactly the same as I do, just i want to use different form element's. My question is how would I be able to use this very same example but in stead of using a date format I want to use it to set a time with the use of select boxes. I would appreciate it very much if someone can give me directions. Kind regards, J. Sanders
[fw-general] Zend_Form not rendering - Plugin Loader not configured??
In summary, I have a basic ZF stack with a shell of Zend_Form: class Form extends Zend_Form { } when I try to echo/render the Form I get this error: Zend_Loader_PluginLoader_Exception: Plugin by name 'FormElements' was not found in the registry; used paths: in .../library/Zend/Loader/PluginLoader.php on line 412 I ensured it wasn't an include's issue by examining the include path from inside the view as well as requiring the Decorator inside the view - which works just fine: ?php require_once('Zend/Form/Decorator/FormElements.php'); ? I posted an issue into JIRA - but Christian told me Please ask for help on the mailing list or at irc.freenode.net #zftalk you are missing some setup for the Plugin Loader. -- so that's what I am doing. I looked online for any docs about configuring the Plugin Loader - but can't seem to find anything. My full issue is - http://zendframework.com/issues/browse/ZF-9739 -- View this message in context: http://zend-framework-community.634137.n4.nabble.com/Zend-Form-not-rendering-Plugin-Loader-not-configured-tp2063703p2063703.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form odd problem
Is it possible for $form-getMessages() to be empty yet $form-getErrors() to contain an error? Here's the issue, I'm validating a ReCaptcha field which is working fine in my Zend_Form. If I forget to enter a value into the ReCaptcha field or if I get it wrong, the error message displays in $form-getMessages(). However, if I correctly type in the ReCaptcha image into the box, $form-getMessages doesn't return any errors however $form-getErrors() returns badCaptcha for the element. Does this make sense? What could be wrong? I have the latest Zend version. Just in case you want to look at the code it's below: -- ZEND_FORM -- $publickey = 'XXX'; $privatekey = 'X'; $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey); $captcha = new Zend_Form_Element_Captcha('captcha', array( 'captcha'= 'ReCaptcha', 'captchaOptions' = array('captcha' = 'ReCaptcha', 'service' = $recaptcha) ) ); $this-addElement($captcha); $this-getElement('captcha')-getCaptcha()-getService()-setOption('theme', 'custom')-setOption('lang', 'en'); $this-getElement('captcha') -setErrorMessages(array('incorrect-captcha-sol' = 'The words you entered did not match the image, please try again.')) -clearDecorators(); -- FORM_VIEW -- div class=iptblock div id=recaptcha_image/div input type=text name=recaptcha_response_field id=recaptcha_response_field style=margin-top:15px;?php echo $this-element-captcha; ? /div -- View this message in context: http://n4.nabble.com/Zend-Form-odd-problem-tp1837256p1837256.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form (get populated values)
Hello, is there any way to get the values inside the form after populate it ? e.g: $myForm= new Default_Form_MyForm; $myForm-populate(array(my_data_here)); And then inside the form to retrieve these values was populated? class Default_Form_MyForm extends Zend_Form { // here i want to retrieve my populated data } Is it possible? Thanks -- View this message in context: http://n4.nabble.com/Zend-Form-get-populated-values-tp1752149p1752149.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form (get populated values)
$this-getValue() and $this-getValues() should do the job. Regards, Saša Stamenković On Mon, Apr 5, 2010 at 11:47 PM, eduardocury l...@eduardocury.net wrote: Hello, is there any way to get the values inside the form after populate it ? e.g: $myForm= new Default_Form_MyForm; $myForm-populate(array(my_data_here)); And then inside the form to retrieve these values was populated? class Default_Form_MyForm extends Zend_Form { // here i want to retrieve my populated data } Is it possible? Thanks -- View this message in context: http://n4.nabble.com/Zend-Form-get-populated-values-tp1752149p1752149.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form text element is always null
Hi, I have a form that successfully uploads a file to the server. I want to improve the form by having a text input. The input is defined as follows in the code that describes the form: $form-addElement('text', 'filterstring'); $textElement=$form-getElement('filterstring'); $textElement-setLabel('Filter by String:'); In the controller for my action (updateAction), I have the following code: $form = $this-importForm(); $uploadedData = $form-getValues(); echo var_dump($uploadedData); 'filterstring' is always NULL, no matter what I have typed into the text input. I have had similar problems with trying to pass the value of checkboxes, but I find the issue with the text input not passing the value to the controller to be extremely aggravating. Am I doing something wrong? My code isn't really different than other examples of Zend_Form I have seen. Thanks, Ethan -- View this message in context: http://n4.nabble.com/Zend-Form-text-element-is-always-null-tp1745680p1745680.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form upload file
Hi, i have found that Zend_Form_Element_File ignore no file option would not work if the form that submited is missing that file element. let's say,there is a form that upload a file to the server, form enctype=multipart/form-data action=/demo/upload method=post any text:input type=text name=any / br / upload file:input type=file name=uploadFile /br / input type=submit value=upload / /form and the Zend_Form as this, ?php class DemoController extends Zend_Controller_Action { public function uploadAction() { $form = new Zend_Form(); $any = new Zend_Form_Element_Text('any'); $form-addElement($any); $uploadFile = new Zend_Form_Element_File('uploadFile'); $uploadFile-setAllowEmpty(true); $form-addElement($uploadFile); if ($this-_request-isPost() $form-isValid($_POST)) { echo 'valid'; } } } then submit the form,that is ok.But if submit the form as this,it is not valid, form enctype=multipart/form-data action=/demo/upload method=post any text:input type=text name=any / br / input type=submit value=upload / /form this form just missing the file element,input type=file name=uploadFile /,but i had set the Zend_Form to allow empty file,ignore no file option. I think this should be a bug. Right? Best Regards
Re: [fw-general] Zend_Form + JQuery + tabs
On Fri, Mar 12, 2010 at 4:45 PM, Mike Wright mike.wri...@mailinator.comwrote: David Mintz wrote: On Fri, Mar 12, 2010 at 1:34 PM, scs sasc...@gmail.com wrote: Hi, I would validate each step's data and save it in session. However, if any previous tab is clicked and there was an attempt to change any validated input, then I would validate that input again. In other words, click 2nd tab-validate 1st tab data and save in session. click 3rd tab-validate 2nd tab data and save in session click submit button - validate 3rd tab data and insert the session-saved+3rd tab's validated data in db (or any operation else) if any previous/validated tab clicked and information is changed on that tab (before the submit is clicked), re-validate that data again. I do not think there is a need to re-submit all tabs' data again once the submit button is clicked. So it doesn't make it into the session unless it's valid. This sounds like a good approach. Question: how do we detect whether they have changed data in a previously-validated tab? Compare POSTed data to what's in the session, obviously. But how expensive is that compared to validating again unconditionally? Especially considering that if it's changed we will definitely validate again anyway. Doesn't all of this become irrelevant if the current subForm is validated and stored on any submission? After that your model/flow can decide which subForm should be presented next. That makes possible previous/next and buttons to arbitrarily select the order of the forms (after all, the user should be able to determine their own workflow, no?). .02 US (not worth much before, a lot less now) Maybe I'm not getting your point. I don't plan to have subforms correspond to tabs one-for-one, because there are multiple models, each with a corresponding subform. I just want to split up groups of fields into tabs for the sake of presentation; there's a single submit button for all. When they move from tab to tab they aren't going to be submitting, but it seems a fine opportunity to processAjax() and validate the current section of the form before it gets hidden from view. -- Support real health care reform: http://phimg.org/ -- David Mintz http://davidmintz.org/
[fw-general] Zend_Form + JQuery + tabs
Embarking on my first ajaxified Zend Form with a JQuery UI-tabbed interface, I am wondering what sort of practices people recommend. Say we have tabs 1, 2 and 3, left to right. Tab 1 is displayed first. They click tab 2. We use a JQuery tabsselect callback to submit only the data from tab 1 for validation. So... in the controller I presume we should call $form-processAjax(...) to validate the $_POSTed data, yes? Back to the client side, the JQuery callback displays errors and returns false if there are any errors, otherwise true and the next tab is displayed. Right? When they finally click the submit button, do we xhr-submit all the data from all the tabs and fields, and validate it all once again? It seems redundant if you do, but risky if you don't. OTOH, with each click on the next tab, you could actually save the successfully validated data from the current tab (in this case, in a database) and carry on. That would obviate the need for re-validating. Then again, as a user I don't expect to save until I actually click a submit button rather than a tab. Comments? -- Support real health care reform: http://phimg.org/ -- David Mintz http://davidmintz.org/
Re: [fw-general] Zend_Form + JQuery + tabs
On Fri, Mar 12, 2010 at 1:34 PM, scs sasc...@gmail.com wrote: Hi, I would validate each step's data and save it in session. However, if any previous tab is clicked and there was an attempt to change any validated input, then I would validate that input again. In other words, click 2nd tab-validate 1st tab data and save in session. click 3rd tab-validate 2nd tab data and save in session click submit button - validate 3rd tab data and insert the session-saved+3rd tab's validated data in db (or any operation else) if any previous/validated tab clicked and information is changed on that tab (before the submit is clicked), re-validate that data again. I do not think there is a need to re-submit all tabs' data again once the submit button is clicked. So it doesn't make it into the session unless it's valid. This sounds like a good approach. Question: how do we detect whether they have changed data in a previously-validated tab? Compare POSTed data to what's in the session, obviously. But how expensive is that compared to validating again unconditionally? Especially considering that if it's changed we will definitely validate again anyway. -- Support real health care reform: http://phimg.org/ -- David Mintz http://davidmintz.org/
Re: [fw-general] Zend_Form + JQuery + tabs
David Mintz wrote: On Fri, Mar 12, 2010 at 1:34 PM, scs sasc...@gmail.com wrote: Hi, I would validate each step's data and save it in session. However, if any previous tab is clicked and there was an attempt to change any validated input, then I would validate that input again. In other words, click 2nd tab-validate 1st tab data and save in session. click 3rd tab-validate 2nd tab data and save in session click submit button - validate 3rd tab data and insert the session-saved+3rd tab's validated data in db (or any operation else) if any previous/validated tab clicked and information is changed on that tab (before the submit is clicked), re-validate that data again. I do not think there is a need to re-submit all tabs' data again once the submit button is clicked. So it doesn't make it into the session unless it's valid. This sounds like a good approach. Question: how do we detect whether they have changed data in a previously-validated tab? Compare POSTed data to what's in the session, obviously. But how expensive is that compared to validating again unconditionally? Especially considering that if it's changed we will definitely validate again anyway. Doesn't all of this become irrelevant if the current subForm is validated and stored on any submission? After that your model/flow can decide which subForm should be presented next. That makes possible previous/next and buttons to arbitrarily select the order of the forms (after all, the user should be able to determine their own workflow, no?). .02 US (not worth much before, a lot less now)
[fw-general] Zend_Form Question
Is there a way to render different parts of the form at a time? I want to render different display groups around a page, so I need to somehow render the forms opening tags, render the display groups around the page with ?= $this-form-getDisplayGroup('part-xx') ?, and then somehow need to render the closing form tags. Is there any way to do this? I know I could copy the HTML tags and manually insert them, but I was just wondering if I could keep the rendering all code outputted... Any help is appreciated... Arthur
[fw-general] Zend_Form + error weirdness
Hi, I'm a bit confused here. Say I have a form: $form = new Zend_Form(); then I set an error on it. $form-addError(It's broken); But when I try and retrieve that error it doesn't work. $form-getErrors(); // returns array(); but: $form-isErrors(); // true. Looking at the code, I see that the getErrors() loops through the elements and uses the element name to show the errors. Various other view helpers etc, also do similar things. The question I have is why is there an addError() method on the form object if the errors you add with it can never be used? I can see the value for subforms or elements as these inherently have names against which to attach the error. I think what I was ultimately going to do (pass a series of specific notes to be rendered after a PRG - in addition to a generic message via FlashMessage), I'll end up doing differently, but this is still a bit of a confusing part of the API for me so any clarifications would be appreciated. Col PS using 1.10.1 -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/]
[fw-general] Zend_Form displayGroup render problem
In Controller: class IndexController extends Zend_Controller_Action { public function init() { $this-form = new RPS_Forms_Build_Ocorrencias(); } public function indexAction() { //Zend Form Elements $values = $this-form-buildForm(); $form = new Zend_Form(); $form-setAction('/process'); $form-addElements($values); $form-addDisplayGroup(array('origem'), 'left'); $form-addDisplayGroup(array('sistema'), 'left1'); $this-view-form = $form; } } In View: div id=esq ?=$this-form-left;? /div div id=nav ?=$this-form-left1;? /div So the problem is: It only renders the Form elements, it doesn´t render the action, so my form isn´t really a form, just a couple of inputs. If I pass the render() method it renders again all the elements. How can I render the groups? Please advice Thanks -- View this message in context: http://n4.nabble.com/Zend-Form-displayGroup-render-problem-tp1556433p1556433.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] zend_form escape help
monk.e.boy wrote: I fear i am being thick, but could someone help me with this code: OK, I was escaping the label, but not the description, so this fixes it: $goods_in_transit-getDecorator('Description')-setOption('escape', false); monk.e.boy -- View this message in context: http://n4.nabble.com/zend-form-escape-help-tp997494p997946.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] zend_form escape help
I fear i am being thick, but could someone help me with this code: $goods_in_transit = new Zend_Form_Element_Text('goods_in_transit'); $label = $goods_in_transit-getDecorator('label'); print_r( $label-getOptions() ); // this prints :: Array ( [tag] = dt ) $label-setOption('escape', false); print_r( $label-getOptions() ); // this prints :: Array ( [tag] = dt [escape] = ) $goods_in_transit-setLabel('Goods in Transit insurance up to') -setDescription('e.g. pound;25,000. (leave blank if not applicable)'); $label = $goods_in_transit-getDecorator('label'); print_r( $label-getOptions() ); // this prints :: Array ( [tag] = dt [escape] = ) It always escapes my pound sign. I have read the docs and the source, but I can't hit that sweet spot :( monk.e.boy -- View this message in context: http://n4.nabble.com/zend-form-escape-help-tp997494p997494.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form suggestion about setElementDecorators()
Hi. I have the following use case: I have a form which I use to override default decorators, element decorators, add prefixes...all forms in the app are extending it. The problem occurs when I try to set decorators on some specific element in concrete form like: ...)-addElement( 'text', 'price', array( 'label' = 'Cena:', 'disableLoadDefaultDecorators' = true, 'decorators' = array( 'viewHelper', array('Label', array('class' = 'someclass')), ) ) )... element never gets those decorators because Zend_Form::setElementDecorators() does not care about 'disableLoadDefaultDecorators' attribute of element. /** * Set all element decorators as specified * * @param array $decorators * @param array|null $elements Specific elements to decorate or exclude from decoration * @param bool $include Whether $elements is an inclusion or exclusion list * @return Zend_Form */ public function setElementDecorators(array $decorators, array $elements = null, $include = true) { if (is_array($elements)) { if ($include) { $elementObjs = array(); foreach ($elements as $name) { if (null !== ($element = $this-getElement($name))) { $elementObjs[] = $element; } } } else { $elementObjs = $this-getElements(); foreach ($elements as $name) { if (array_key_exists($name, $elementObjs)) { unset($elementObjs[$name]); } } } } else { $elementObjs = $this-getElements(); } foreach ($elementObjs as $element) { $element-setDecorators($decorators); } $this-_elementDecorators = $decorators; return $this; } maybe this method needs an update, where disableLoadDefaultDecorators can be checked and element excluded. What do you think? Or I can go with overriding setElementDecorators :P Regards, Saša Stamenković. -- View this message in context: http://n4.nabble.com/Zend-Form-suggestion-about-setElementDecorators-tp989752p989752.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form Int filter
Fixed with -addElement( 'text', 'name', array( 'label' = 'Lab:', 'filters' = array('Int', 'Null'), 'required' = true ) this requires zf 1.10+ umpirsky wrote: Hi. I have several fields of int type which I have in my form. I want to get integer when I get values from form after submission. So, I attached int filter like: -addElement( 'text', 'name', array( 'label' = 'Lab:', 'filters' = array('Int'), 'required' = true ) This works ok, but when I render empty form, I get zero in my input, which looks very odd. I want empty field when nothing entered. Should I use new Zend_Filter_Null in combination with int filter, or there is sth else I can do? Regards, Saša Stamenković. -- View this message in context: http://n4.nabble.com/Zend-Form-Int-filter-tp976819p978774.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form Int filter
Hi. I have several fields of int type which I have in my form. I want to get integer when I get values from form after submission. So, I attached int filter like: -addElement( 'text', 'name', array( 'label' = 'Lab:', 'filters' = array('Int'), 'required' = true ) This works ok, but when I render empty form, I get zero in my input, which looks very odd. I want empty field when nothing entered. Should I use new Zend_Filter_Null in combination with int filter, or there is sth else I can do? Regards, Saša Stamenković. -- View this message in context: http://n4.nabble.com/Zend-Form-Int-filter-tp976819p976819.html Sent from the Zend Framework mailing list archive at Nabble.com.
RE: [fw-general] Zend_Form decorators webinar tomorrow
Incase anyone else tried to use the link to get to the webinar and found it to be broken. The webinar is also listed here - http://www.zend.com/en/company/events/ -Original Message- From: Matthew Weier O'Phinney [mailto:matt...@zend.com] Sent: Tuesday, December 15, 2009 3:25 PM To: fw-...@lists.zend.com Cc: fw-general@lists.zend.com Subject: [fw-general] Zend_Form decorators webinar tomorrow Hey, all -- I'm giving a webinar on Zend_Form decorators tomorrow at 12pm EST: http://short.ie/62entq I'll be covering a variety of techniques, from writing a simple one-off decorator, to combining decorators to achieve composite markup, to creating an element and decorator that create composite markup (think: date or time input). If you've ever felt mystified by decorators, come join me tomorrow! (Yes, the webinar recording will be released online in the future.) -- Matthew Weier O'Phinney Project Lead| matt...@zend.com Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend_Form - Viewscript
The problem with this is that you still can't add information inbetween each input. For instance: label for=Mine:/labelinput type=radio / Reference label for=Mine:/labelinput type=radio / Reference label for=Mine:/labelinput type=radio / Reference To accomplish this you still have to extend the formRadio view helper and modify. Am I wrong? Julian Davchev wrote: This solution should work for you. It fixes two issues: - attributes leaking into html..when they shouldn't - you get your selects,radio,checkbox and whatever like that working ?php //we need this trick due to: http://framework.zend.com/issues/browse/ZF-3052 //Expand the list as needed $attributesWhiteList = array('multiple','class','style','onClick','onChange','checked','disabled'); $attributes = $this-element-getAttribs(); $selectOptions = null; if (method_exists($this-element,'getMultiOptions')) { $selectOptions = $this-element-getMultiOptions(); } foreach ($attributes as $attrib = $value) { if (!in_array($attrib,$attributesWhiteList)) { unset($attributes[$attrib]); } } ? div class=?= $this-class ? ?= $this-formLabel($this-element-getName(), $this-element-getLabel()) ? ?= $this-{$this-element-helper}( $this-element-getName(), $this-element-getValue(), $attributes, $selectOptions ) ? ?= $this-formErrors($this-element-getMessages()) ? div class=hint?= $this-element-getDescription() ?/div /div jmazzi wrote: I am using the example from http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript to create a custom viewscript. i used the example from the manual but it wont render select box options. It works for all other input types (text etc) and even works to create the select box. But the options do not load (addMultioptions). -- View this message in context: http://n4.nabble.com/Zend-Form-Viewscript-tp651615p964417.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form - Viewscript
I'm wrong, something like this would work: $selectOptions = $this-element-getMultiOptions(); $custom = array(); foreach($selectOptions as $value = $label){ ? div class=radioinput type=radio value=?=$value? /?=$label?/div ?}? The only problem with this is that you have to re write all the disable, multiple, etc checks. strick wrote: The problem with this is that you still can't add information inbetween each input. For instance: label for=Mine:/labelinput type=radio / Reference label for=Mine:/labelinput type=radio / Reference label for=Mine:/labelinput type=radio / Reference To accomplish this you still have to extend the formRadio view helper and modify. Am I wrong? Julian Davchev wrote: This solution should work for you. It fixes two issues: - attributes leaking into html..when they shouldn't - you get your selects,radio,checkbox and whatever like that working ?php //we need this trick due to: http://framework.zend.com/issues/browse/ZF-3052 //Expand the list as needed $attributesWhiteList = array('multiple','class','style','onClick','onChange','checked','disabled'); $attributes = $this-element-getAttribs(); $selectOptions = null; if (method_exists($this-element,'getMultiOptions')) { $selectOptions = $this-element-getMultiOptions(); } foreach ($attributes as $attrib = $value) { if (!in_array($attrib,$attributesWhiteList)) { unset($attributes[$attrib]); } } ? div class=?= $this-class ? ?= $this-formLabel($this-element-getName(), $this-element-getLabel()) ? ?= $this-{$this-element-helper}( $this-element-getName(), $this-element-getValue(), $attributes, $selectOptions ) ? ?= $this-formErrors($this-element-getMessages()) ? div class=hint?= $this-element-getDescription() ?/div /div jmazzi wrote: I am using the example from http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript to create a custom viewscript. i used the example from the manual but it wont render select box options. It works for all other input types (text etc) and even works to create the select box. But the options do not load (addMultioptions). -- View this message in context: http://n4.nabble.com/Zend-Form-Viewscript-tp651615p964431.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form decorators webinar tomorrow
Hey, all -- I'm giving a webinar on Zend_Form decorators tomorrow at 12pm EST: http://short.ie/62entq I'll be covering a variety of techniques, from writing a simple one-off decorator, to combining decorators to achieve composite markup, to creating an element and decorator that create composite markup (think: date or time input). If you've ever felt mystified by decorators, come join me tomorrow! (Yes, the webinar recording will be released online in the future.) -- Matthew Weier O'Phinney Project Lead| matt...@zend.com Zend Framework | http://framework.zend.com/
[fw-general] Zend_Form translate messages
Hi. If anyone have po file with all error messages http://framework.zend.com/manual/en/zend.validate.messages.html it would be nice to share ;) Othervise, I'll make one and share. PS Dont ask me which language I need :) Regards, Saša Stamenković. -- View this message in context: http://n4.nabble.com/Zend-Form-translate-messages-tp962733p962733.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form without MVC problem
So easy... $form = new Forms_YouForm(); $view = new Zend_View(); $form-setView( $view ); echo $form; -- View this message in context: http://n4.nabble.com/Zend-Form-without-MVC-problem-tp657457p948679.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form initial values
Hi zf gurus. I have one quick seach form (GET method) in the sidebar. On submit I fix url to be zend style /key/val/key2/val2/ with window.location = this.attr('action') + '/' + this.serialize().replace(//g, '/').replace(/=/g, '/'); After submit form use to set default value with values from URL, but now that is just not the case. I can't find where the problem is, any tips? If someone know where this values are set in the code, I'd like to know and debug. Regards, Saša Stamenkvić. -- View this message in context: http://n4.nabble.com/Zend-Form-initial-values-tp788087p788087.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form initial values
Why don't you use post? This way a person can easy change the values you have set in the form by changing the url manualy. On Thu, Nov 26, 2009 at 9:16 AM, umpirsky umpir...@gmail.com wrote: Hi zf gurus. I have one quick seach form (GET method) in the sidebar. On submit I fix url to be zend style /key/val/key2/val2/ with window.location = this.attr('action') + '/' + this.serialize().replace(//g, '/').replace(/=/g, '/'); After submit form use to set default value with values from URL, but now that is just not the case. I can't find where the problem is, any tips? If someone know where this values are set in the code, I'd like to know and debug. Regards, Saša Stamenkvić. -- View this message in context: http://n4.nabble.com/Zend-Form-initial-values-tp788087p788087.html Sent from the Zend Framework mailing list archive at Nabble.com. -- Met vriendelijke groet, Jigal Sanders A.J. Ernststraat 739 1082 LK Amsterdam Mobiel: 06-42111489
Re: [fw-general] Zend_Form initial values
Thats what I want. Reasons: - SEO - Pagination - Back button - ... Example http://www.mobile.de/ quick search. Regards, Saša Stamenković On Thu, Nov 26, 2009 at 9:23 AM, Jigal sanders jigalroe...@gmail.comwrote: Why don't you use post? This way a person can easy change the values you have set in the form by changing the url manualy. On Thu, Nov 26, 2009 at 9:16 AM, umpirsky umpir...@gmail.com wrote: Hi zf gurus. I have one quick seach form (GET method) in the sidebar. On submit I fix url to be zend style /key/val/key2/val2/ with window.location = this.attr('action') + '/' + this.serialize().replace(//g, '/').replace(/=/g, '/'); After submit form use to set default value with values from URL, but now that is just not the case. I can't find where the problem is, any tips? If someone know where this values are set in the code, I'd like to know and debug. Regards, Saša Stamenkvić. -- View this message in context: http://n4.nabble.com/Zend-Form-initial-values-tp788087p788087.html Sent from the Zend Framework mailing list archive at Nabble.com. -- Met vriendelijke groet, Jigal Sanders A.J. Ernststraat 739 1082 LK Amsterdam Mobiel: 06-42111489
[fw-general] Zend_Form and fields metacommand doesn't work
Hi all, yesterday I have found metacommands in manual at http://framework.zend.com/manual/en/zend.filter.input.html#zend.filter.input.metacommands.fields I want to compare to password fields with the Identical validator. So I build my form shown at http://paste2.org/p/532112 When I use this to validate through the fields metacommand, I get the following error: No token was provided to match against. Can someone explain me how to use it right? Regards, Dennis Becker
Re: [fw-general] Zend_Form: possible to disable some multi options in radio button
Hi Gerard, thanks, that pointed me in the right direction. Works like expected. Now I still have the little problem, that I want to grey out the label around the disabled radio button. From the code I guess its impossible to add a special css class for these label tags without hacking the code or extending the Zend_View_Helper_FormRadio class myself. Thanks and best regards, Ralf
Re: [fw-general] Zend_Form: possible to disable some multi options in radio button
Hi Ralf, thanks, that pointed me in the right direction. Works like expected. You're welcome of course :-) Now I still have the little problem, that I want to grey out the label around the disabled radio button. From the code I guess its impossible to add a special css class for these label tags without hacking the code or extending the Zend_View_Helper_FormRadio class myself. It doesn't seem so. It's not documented either, so I think it would be quite a valid issue to report and propose a patch for in the issue tracker. Maybe something like labelClassDisabled as a helper option might be appropriate. Gerard
[fw-general] Zend_Form: possible to disable some multi options in radio button
Hi, I have a radio button element with several options. I would like to disable some of them. They should be shown but they should not be able to be activated. With this I can only disable all radio buttons together: $form-getElement('selection')-setAttrib('disable', 'disable'); Any chance to get this done? Thanks and best regards, Ralf
Re: [fw-general] Zend_Form: possible to disable some multi options in radio button
Hi Ralf, I have a radio button element with several options. I would like to disable some of them. They should be shown but they should not be able to be activated. With this I can only disable all radio buttons together: $form-getElement('selection')-setAttrib('disable', 'disable'); By looking at Zend_View_Helper_FormRadio, it seems that you can pass an array of disabled values to the disabled option. HTH. drm / Gerard
[fw-general] Zend_Form label decorator duplicated id
I have element decorators array( 'ViewHelper', array(array('td' = 'HtmlTag'), array('tag' = 'td', 'style' = 'width: 360px;')), array('Label', array('tag' = 'td', 'requiredSuffix' = ' *')), array(array('tr' = 'HtmlTag'), array('tag' = 'tr')), array(array('tbody' = 'HtmlTag'), array('tag' = 'tbody')), array(array('table' = 'HtmlTag'), array('tag' = 'table', 'class' = 'tiny')), array(array('separator' = 'HtmlTag'), array('tag' = 'div', 'class' = 'separator')) ) and form with 3 subforms. I set each subform $this-setElementsBelongTo() to avoid name collision, BUT I get label (td) id collision, it's always td id=$elementName-label !!! Any idea? -- View this message in context: http://old.nabble.com/Zend_Form-label-decorator-duplicated-id-tp26263730p26263730.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form and arrays
2009/10/22 Krzysztof Szatanik z...@gazeta.ie As you can see even if i get form values in request as i wanted, they aren't recognized by Zend_Form. Output of $form-getValues() is different from expected, and even fields aren't recognized, so i can use Zend_Form only to generate HTML form but not to filter and validate submited form. Assuming it's a post: $form-isValid($request-getPost()); $data = $form-getValues(); - pw
Re: [fw-general] Zend_Form and arrays
Your Zend_Form is a POST method. You can also do it this way in your controller. $form = new Default_Form_FormName(); // instantiate the form $this-view-form = $form; // form for the view //after submitting the form if($this-getRequest()-isPost()) { // if the form is a post $formData = $this-getRequest()-getPost(); // get the data from the post if ($form-isValid($formData)) { //if the post if valid $values = $form-getValues(); //values of the form //make an array $data=array( 'er1'=$values['er1'], 'er2'=$values['er2'], ); } } On Sat, Oct 24, 2009 at 8:03 AM, Peter Warnock petewarn...@gmail.comwrote: 2009/10/22 Krzysztof Szatanik z...@gazeta.ie As you can see even if i get form values in request as i wanted, they aren't recognized by Zend_Form. Output of $form-getValues() is different from expected, and even fields aren't recognized, so i can use Zend_Form only to generate HTML form but not to filter and validate submited form. Assuming it's a post: $form-isValid($request-getPost()); $data = $form-getValues(); - pw -- Shaun J. Farrell Washington, DC (202) 713-5241 www.farrelley.com
[fw-general] Zend_Form and arrays
Hi I have some issues with Zend_Form and getting values as arrays. For example - i have 2 elements - e1 and e2 and i want them as array (arr): Something like this: [arr] = Array ( [e1] = val1 [e2] = val2 ) Closest form design i can get is this code: $form = new Zend_Form(); $form-addElement( 'text', 'e1', array( 'belongsTo' = 'arr', 'label' = 'e1', )); $form-addElement( 'text', 'e2', array( 'belongsTo' = 'arr', 'label' = 'e2', )); $form-addElement( 'submit', 'submit', array()); $form-setDefaults($this-getRequest()-getParams()); echo 'preForm values: '; print_r( $form-getValues() ); echo '/pre'; echo 'preRequest params: '; print_r( $this-getRequest()-getParams() ); echo '/pre'; echo $form; But, there is still huge problem: Sample output: Form values: Array ( [e1] = [e2] = [submit] = submit ) Request params: Array ( [controller] = test [action] = index [module] = default [arr] = Array ( [e1] = val1 [e2] = val2 ) [submit] = submit ) As you can see even if i get form values in request as i wanted, they aren't recognized by Zend_Form. Output of $form-getValues() is different from expected, and even fields aren't recognized, so i can use Zend_Form only to generate HTML form but not to filter and validate submited form. I tried in many ways using different combination of isArray, belongsTo, name and nothing works... Any solutions to this problem that i can still use Zend_Form booth to generate form and then to filter/validate submitted data? -- Best Regards, KS
Re: [fw-general] Zend_Form and arrays
I think you need to add this to your form: $form-setIsArray(true); If you then access (that's what I do) the form values in a controller like that: $this-getRequest()-getPost('arr') ...you should get the expected array. Just take care that you have to set the form name to match the expected array name. I use the constructor for that: $form = new Zend_Form(array ('name' ='arr')); Jules Piccotti 2009/10/22 Krzysztof Szatanik z...@gazeta.ie: Hi I have some issues with Zend_Form and getting values as arrays. For example - i have 2 elements - e1 and e2 and i want them as array (arr): Something like this: [arr] = Array ( [e1] = val1 [e2] = val2 ) Closest form design i can get is this code: $form = new Zend_Form(); $form-addElement( 'text', 'e1', array( 'belongsTo' = 'arr', 'label' = 'e1', )); $form-addElement( 'text', 'e2', array( 'belongsTo' = 'arr', 'label' = 'e2', )); $form-addElement( 'submit', 'submit', array()); $form-setDefaults($this-getRequest()-getParams()); echo 'preForm values: '; print_r( $form-getValues() ); echo '/pre'; echo 'preRequest params: '; print_r( $this-getRequest()-getParams() ); echo '/pre'; echo $form; But, there is still huge problem: Sample output: Form values: Array ( [e1] = [e2] = [submit] = submit ) Request params: Array ( [controller] = test [action] = index [module] = default [arr] = Array ( [e1] = val1 [e2] = val2 ) [submit] = submit ) As you can see even if i get form values in request as i wanted, they aren't recognized by Zend_Form. Output of $form-getValues() is different from expected, and even fields aren't recognized, so i can use Zend_Form only to generate HTML form but not to filter and validate submited form. I tried in many ways using different combination of isArray, belongsTo, name and nothing works... Any solutions to this problem that i can still use Zend_Form booth to generate form and then to filter/validate submitted data? -- Best Regards, KS
Re: [fw-general] Zend_Form - select - option bgcolour
Hi, I dont use php for that. In my project a nned to set background color as value of options so just after generated form i write some jquery code: $(document).ready(function(){ $('#select option').each(function(i) { $(this).css('background-color', $(this).attr('label')); }); }); PHPScriptor wrote: Hello there, I think it's not possible to do with Zend Forms, but can anyone give me some advice how I could do it the best way. Something like: making the Zend Form and output it step by step in the view? I want to set every option in my select a different background-color... select ... option style=background-color:green value=B title=Bnbsp;nbsp;nbsp;/option option style=background-color:red value=A title=Anbsp;nbsp;nbsp;/option option style=background-color:blue value=C title=C nbsp;nbsp;nbsp;/option /select -- View this message in context: http://www.nabble.com/Zend_Form---select---option-bgcolour-tp22073845p25525955.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form using Zend_Config
Hi, I'm trying to create a form using Zend_Form and Zend_Config_Ini, however, I'm having trouble creating a select list. How do you add options to the select list using the the config file format? elements.test.type = select elements.test.options.label = Test elements.test.options.required = true Thanks, Greg
Re: [fw-general] Zend_Form using Zend_Config
-- Koph Digital ad...@koph.co.uk wrote (on Tuesday, 15 September 2009, 11:38 PM +0100): I’m trying to create a form using Zend_Form and Zend_Config_Ini, however, I’m having trouble creating a select list. How do you add options to the select list using the the config file format? elements.test.type = select elements.test.options.label = Test elements.test.options.required = true Use the configuration key multiOptions: elements.test.options.multiOptions.foo = Foo -- Matthew Weier O'Phinney Project Lead| matt...@zend.com Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend_Form Patch (ZF-5412 and ZF-4915)
-- Tobias Petry tobias_pe...@hotmail.com wrote (on Friday, 11 September 2009, 04:25 PM -0700): just wanted to announce a new patch for ZF-5412. Could somebody with comit priveleges take care of it? It is unit tested and breaks no other test. I saw the patch come in today, and flagged it for review. Have you signed a CLA? If not, can you please sign one and send it in? (We cannot apply your patches unless you have.) -- Matthew Weier O'Phinney Project Lead| matt...@zend.com Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend_Form Patch (ZF-5412 and ZF-4915)
I have signed an CLA long ago and have been successfully processed. Anything not correct? Then i'll resend the CLA. -- View this message in context: http://www.nabble.com/Zend_Form-Patch-%28ZF-5412-and-ZF-4915%29-tp25409842p25425583.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form Patch (ZF-5412 and ZF-4915)
Hi, just wanted to announce a new patch for ZF-5412. Could somebody with comit priveleges take care of it? It is unit tested and breaks no other test. Tobias Petry -- View this message in context: http://www.nabble.com/Zend_Form-Patch-%28ZF-5412-and-ZF-4915%29-tp25409842p25409842.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form File Element / Decorator - Extremely Confuzzled
Hi there~ I'm relatively new to ZF but have enjoyed using it so far. The main issue I've had with ZF is with it's Form and Decorator aspects. After going through God knows how many articles/blogs/posts and what not, I thought I finally had a grasp of it. Things were working okay. I created a standard set of decorators (for Elements, Buttons and Forms) based on an example I saw. Recently however, I realised that I needed to add in some File Input fields into one of the forms. None of the above decorators worked with it. At which point, I decided to use ViewScripts on all the forms since it provides greater room to stylise/organise the form. The code I'm currently using, looks something like the following: site/application/forms/RegisterForm.php class ProjectStartContactPersonForm extends Gid_Form { public function init () { $this-setAction('') -setMethod('post') -setAttrib('id','formStartProject') -setAttrib('enctype', 'multipart/form-data'); $this-addElement('text', 'textName', array('label' = 'Given Name')); $oName = $this-getElement('textName') -setRequired(true) -setDecorators(array('ViewHelper', 'Errors')); $this-addElement('file', 'filePhotograph'); $oPhotograph = $this-getElement('filePhotograph') -setRequired(true); $this-addElement('submit', 'submitRegister', array('label' = 'Done')); $oContactPersonSubmit = $this-getElement('submitRegister'); $oContactPersonSubmit-setDecorators(array('ViewHelper', 'Errors')); $this-setDecorators(array(array('ViewScript', array('viewScript' = 'forms/RegisterForm.phtml'; } } site/application/views/scripts/forms/RegisterForm.phtml div id='iDivRegister' form action='' method='post' table tr tdlabel for='textName'Name:/label/td td?php echo $this-element-textName; ?/td /tr tr tdlabel for='filePhotograph'Photo:/label/td td?php echo $this-element-filePhotograph; ?/td /tr tr td/td td?php echo $this-element-submitRegister; ?/td /tr /table /form /div From RegisterForm.php I had to change $this-addElement('file', 'filePhotograph', array('label' = 'Photo')); to get it to work. prior to that, the File Input element was being displayed twice. Additionally, if -setDecorators(array('ViewHelper', 'Errors')) was attached to the File Input object, it would throw the error Warning: No file decorator found... unable to render file element in C:\xampp\xampp\php\PEAR\Zend\Form\Element.php on line 1929. I honestly can't understand what the issue is or how I'm supposed to resolve it. All the searching and reading I did lead me to more questions and no solution. Some of them dealt with the lack of a File Input Class in ZF (which I believe was a somewhat early release), while others used custom classes for things which didn't really clarify anything for me. Currently, the File Input Element is rendered as follows: tr tdlabel for='filePhotograph'Photo:/label/td td dt id=filePhotograph-labelnbsp;/dt ddinput type=file name=filePhotograph id=filePhotograph/dd /td /tr I would like to get it outside of those dt/dd tags (which suggest the default ZF Decorators are being applied). ZF Documentation I find stragely lacking in the various methods/variables/parameters to use. If anyone knows of a better reference, it's sure to help a great deal. I would greatly appreciate any help anyone can provde me on this. Thanks~ -- View this message in context: http://www.nabble.com/Zend_Form-File-Element---Decorator---Extremely-Confuzzled-tp25365664p25365664.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form File Element / Decorator - Extremely Confuzzled
2009/9/9 Daniel Latter dan.lat...@gmail.com Hi, Have a look at this: http://www.slideshare.net/NickBelhomme/zend-framework-form-mastering-decorators Also regarding your code, the HtmlTag decorator is being applied so you can try and set that, also you can try and clear the default decorators. The *default* *decorators* on an element are: • ViewHelper • Errors • Description (only renders if a description is set) • HtmlTag • Label Try $element-*removeDecorator*('HtmlTag '); Thanks Daniel 2009/9/9 Jayawi jayawiper...@gmail.com Hi there~ I'm relatively new to ZF but have enjoyed using it so far. The main issue I've had with ZF is with it's Form and Decorator aspects. After going through God knows how many articles/blogs/posts and what not, I thought I finally had a grasp of it. Things were working okay. I created a standard set of decorators (for Elements, Buttons and Forms) based on an example I saw. Recently however, I realised that I needed to add in some File Input fields into one of the forms. None of the above decorators worked with it. At which point, I decided to use ViewScripts on all the forms since it provides greater room to stylise/organise the form. The code I'm currently using, looks something like the following: site/application/forms/RegisterForm.php class ProjectStartContactPersonForm extends Gid_Form { public function init () { $this-setAction('') -setMethod('post') -setAttrib('id','formStartProject') -setAttrib('enctype', 'multipart/form-data'); $this-addElement('text', 'textName', array('label' = 'Given Name')); $oName = $this-getElement('textName') -setRequired(true) -setDecorators(array('ViewHelper', 'Errors')); $this-addElement('file', 'filePhotograph'); $oPhotograph = $this-getElement('filePhotograph') -setRequired(true); $this-addElement('submit', 'submitRegister', array('label' = 'Done')); $oContactPersonSubmit = $this-getElement('submitRegister'); $oContactPersonSubmit-setDecorators(array('ViewHelper', 'Errors')); $this-setDecorators(array(array('ViewScript', array('viewScript' = 'forms/RegisterForm.phtml'; } } site/application/views/scripts/forms/RegisterForm.phtml div id='iDivRegister' form action='' method='post' table tr tdlabel for='textName'Name:/label/td td?php echo $this-element-textName; ?/td /tr tr tdlabel for='filePhotograph'Photo:/label/td td?php echo $this-element-filePhotograph; ?/td /tr tr td/td td?php echo $this-element-submitRegister; ?/td /tr /table /form /div From RegisterForm.php I had to change $this-addElement('file', 'filePhotograph', array('label' = 'Photo')); to get it to work. prior to that, the File Input element was being displayed twice. Additionally, if -setDecorators(array('ViewHelper', 'Errors')) was attached to the File Input object, it would throw the error Warning: No file decorator found... unable to render file element in C:\xampp\xampp\php\PEAR\Zend\Form\Element.php on line 1929. I honestly can't understand what the issue is or how I'm supposed to resolve it. All the searching and reading I did lead me to more questions and no solution. Some of them dealt with the lack of a File Input Class in ZF (which I believe was a somewhat early release), while others used custom classes for things which didn't really clarify anything for me. Currently, the File Input Element is rendered as follows: tr tdlabel for='filePhotograph'Photo:/label/td td dt id=filePhotograph-labelnbsp;/dt ddinput type=file name=filePhotograph id=filePhotograph/dd /td /tr I would like to get it outside of those dt/dd tags (which suggest the default ZF Decorators are being applied). ZF Documentation I find stragely lacking in the various methods/variables/parameters to use. If anyone knows of a better reference, it's sure to help a great deal. I would greatly appreciate any help anyone can provde me on this. Thanks~ -- View this message in context: http://www.nabble.com/Zend_Form-File-Element---Decorator---Extremely-Confuzzled-tp25365664p25365664.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form File Element / Decorator - Extremely Confuzzled
Take a look into the FAQ where the problem, the reason and the solution is described: http://framework.zend.com/wiki/display/ZFFAQ/Forms Greetings Thomas Weidner, I18N Team Leader, Zend Framework http://www.thomasweidner.com - Original Message - From: Jayawi jayawiper...@gmail.com To: fw-general@lists.zend.com Sent: Wednesday, September 09, 2009 4:03 PM Subject: [fw-general] Zend_Form File Element / Decorator - Extremely Confuzzled Hi there~ I'm relatively new to ZF but have enjoyed using it so far. The main issue I've had with ZF is with it's Form and Decorator aspects. After going through God knows how many articles/blogs/posts and what not, I thought I finally had a grasp of it. Things were working okay. I created a standard set of decorators (for Elements, Buttons and Forms) based on an example I saw. Recently however, I realised that I needed to add in some File Input fields into one of the forms. None of the above decorators worked with it. At which point, I decided to use ViewScripts on all the forms since it provides greater room to stylise/organise the form. The code I'm currently using, looks something like the following: site/application/forms/RegisterForm.php class ProjectStartContactPersonForm extends Gid_Form { public function init () { $this-setAction('') -setMethod('post') -setAttrib('id','formStartProject') -setAttrib('enctype', 'multipart/form-data'); $this-addElement('text', 'textName', array('label' = 'Given Name')); $oName = $this-getElement('textName') -setRequired(true) -setDecorators(array('ViewHelper', 'Errors')); $this-addElement('file', 'filePhotograph'); $oPhotograph = $this-getElement('filePhotograph') -setRequired(true); $this-addElement('submit', 'submitRegister', array('label' = 'Done')); $oContactPersonSubmit = $this-getElement('submitRegister'); $oContactPersonSubmit-setDecorators(array('ViewHelper', 'Errors')); $this-setDecorators(array(array('ViewScript', array('viewScript' = 'forms/RegisterForm.phtml'; } } site/application/views/scripts/forms/RegisterForm.phtml div id='iDivRegister' form action='' method='post' table tr tdlabel for='textName'Name:/label/td td?php echo $this-element-textName; ?/td /tr tr tdlabel for='filePhotograph'Photo:/label/td td?php echo $this-element-filePhotograph; ?/td /tr tr td/td td?php echo $this-element-submitRegister; ?/td /tr /table /form /div From RegisterForm.php I had to change $this-addElement('file', 'filePhotograph', array('label' = 'Photo')); to get it to work. prior to that, the File Input element was being displayed twice. Additionally, if -setDecorators(array('ViewHelper', 'Errors')) was attached to the File Input object, it would throw the error Warning: No file decorator found... unable to render file element in C:\xampp\xampp\php\PEAR\Zend\Form\Element.php on line 1929. I honestly can't understand what the issue is or how I'm supposed to resolve it. All the searching and reading I did lead me to more questions and no solution. Some of them dealt with the lack of a File Input Class in ZF (which I believe was a somewhat early release), while others used custom classes for things which didn't really clarify anything for me. Currently, the File Input Element is rendered as follows: tr tdlabel for='filePhotograph'Photo:/label/td td dt id=filePhotograph-labelnbsp;/dt ddinput type=file name=filePhotograph id=filePhotograph/dd /td /tr I would like to get it outside of those dt/dd tags (which suggest the default ZF Decorators are being applied). ZF Documentation I find stragely lacking in the various methods/variables/parameters to use. If anyone knows of a better reference, it's sure to help a great deal. I would greatly appreciate any help anyone can provde me on this. Thanks~ -- View this message in context: http://www.nabble.com/Zend_Form-File-Element---Decorator---Extremely-Confuzzled-tp25365664p25365664.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form clearErrorMessages vs. clone the object
What exactly is the feature request? For batch form operations, a new Zend_Form method named something like clearAndPrepForRePopulate(). It would recursively clearAllMessages(), including those in all elements and subForms, as well as set _errorsExist to FALSE. So it would like: $form = getForm(); foreach($dataSet as $record) { $form-populate($record); if($form-isValid) // do CRUD... else // handle errors... $form-clearAndPrepForRePopulate(); } If you check out Zend_Form, it has been designed such that when its cloned, it will actually enforce cloning throughout all of its consumed objects (elements, sub-forms, and display groups). So it is already capable of being safely cloned. Thanks for the confirmation that cloning is the best way. I'd guess that a clearAndPrepForRePopulate() method would be faster than cloning, but for now I'll just create a static $form and clone it for each iteration of the batch operation. If performance is poor I'll extend Zend_Form and try my own clearAndPrepForRePopulate(). Thanks! Chris -- View this message in context: http://www.nabble.com/Zend_Form-clearErrorMessages-vs.-clone-the-object-tp25285029p25373853.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form File Element / Decorator - Extremely Confuzzled
Thanks heaps Daniel and Thomas. I had actually visited that particular FAQ page before, but I thought it a dead-end or login-required page when in fact I now realise that it was due to the horrible internet connection that I have here that the FAQ questions failed to render as a link. In any case, the FAQ cleared up the confusion I had on the file element. At the moment, going through the slides to see what else I can learn. Thanks again! :) -- View this message in context: http://www.nabble.com/Zend_Form-File-Element---Decorator---Extremely-Confuzzled-tp25365664p25377044.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form clearErrorMessages vs. clone the object
Is there a better way? If not, is this a reasonable feature request, that is, to _really_ clear all messages so the object can be reused for batch ops. What exactly is the feature request? If you check out Zend_Form, it has been designed such that when its cloned, it will actually enforce cloning throughout all of its consumed objects (elements, sub-forms, and display groups). So it is already capable of being safely cloned. http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Form.php In general, cloning is a great object-oriented technique for doing exactly what you want. Also, generally speaking, cloning is typically (depending on the implementation of __clone in the target class), much faster than building an object graph from scratch. Cheers! -ralph
[fw-general] Zend_Form clearErrorMessages vs. clone the object
When importing data, say, from a CSV, I'd like to avoid rebuilding my form object every time (it is built up from a somewhat complex config). clearErrorMessages() looks like what I need, except that it doesn't appear to clear all messages from all elements and subforms, and it doesn't set _errorsExist to false. So instead, I'm just going to clone a copy of the original form object as I iterate over the data. Is there a better way? If not, is this a reasonable feature request, that is, to _really_ clear all messages so the object can be reused for batch ops. -- View this message in context: http://www.nabble.com/Zend_Form-clearErrorMessages-vs.-clone-the-object-tp25285029p25285029.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form save to ini
On Saturday 15 August 2009 07:31:37 UpNow wrote: now is the edit form, so i should give the form elements their values read from db. which method use? $form-??? Help me! Thanks.:-D $form-getElement('elementName') -setValue('foo'); or $form-populate($data); Also, http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.elements.values and, http://framework.zend.com/apidoc/core/
[fw-general] Zend_Form save to ini
Any chance to convert Zend_Form object to .ini format? How to achieve this? -- regards takeshin -- View this message in context: http://www.nabble.com/Zend_Form-save-to-ini-tp24979523p24979523.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form save to ini
On Saturday 15 August 2009 00:21:06 admirau wrote: Any chance to convert Zend_Form object to .ini format? How to achieve this? http://framework.zend.com/manual/en/zend.form.quickstart.html#zend.form.quickstart.config
Re: [fw-general] Zend_Form save to ini
What method should i use if i want to give input values to the element of the form(which is configed by .ini) my code: $config = new Zend_Config_Ini($place, $groupname); $form = new Zend_Form($config-user-edit); now is the edit form, so i should give the form elements their values read from db. which method use? $form-??? Help me! Thanks.:-D -- View this message in context: http://www.nabble.com/Zend_Form-save-to-ini-tp24979523p24981721.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Zend_Form - Adding CSS classnames to multiCheckbox inputs
On Tue, Aug 11, 2009 at 11:07 AM, Hector Virgen djvir...@gmail.com wrote: I am building a form that uses the multiCheckbox form element. I need to add class names to specific checkboxes for javascript purposes. Is there a way to do that? -- Hector Why not navigate the dom with javascript? jQuery makes this very easy. - pw
Re: [fw-general] Zend_Form - Adding CSS classnames to multiCheckbox inputs
Thanks for the reply, Peter. I could walk the dom, and in fact I'm using jQuery, but I'm shooting more for a pattern-based approach to accomplishing this task. Here's a little more background as to why I need (er, want) CSS class names. I am building a search form that contains a multiCheckbox element with 5 options: 104 = Fruit 125 = Vegetables 393 = Water 442 = Soda 570 = Beer Some of the options have their own configuration settings to further refine how that option is searched. Those fields are placed in a fieldset: fieldset id=fieldset-food /* elements that affect how food is searched */ /fieldset So, in jQuery, I need to find all of the food options and place a configure button next to them, which shows/hides the related fieldset in a modal window when clicked. The problem is, without class names it is difficult to determine which options are food' and which are drinks. My current workaround is to hard-code my javascript to find the fruit and vegetables options and tie them to the food fieldset, but I would much rather give them a class name so that it works for new categories without the need to modify the javascript. Another option I've considered, although a bit ugly, is to prepend the value with the type: food-104 = Fruit food-125 = Vegetables drink-393 = Water drink-442 = Soda drink-570 = Beer But this would make things a bit uglier when working with the submitted values. Unless I'm mistaken, I think there are two other viable options: 1. Disable escaping and wrap the label in a span: 104 = span class=foodFruit/span 2. Create a new (or extend) formMultiCheckbox helper to accept per-option attributes. As a lazy programmer, I think I'm going to try option #1 and see how it goes. :) -- Hector On Thu, Aug 13, 2009 at 1:14 AM, Peter Warnock petewarn...@gmail.comwrote: On Tue, Aug 11, 2009 at 11:07 AM, Hector Virgen djvir...@gmail.comwrote: I am building a form that uses the multiCheckbox form element. I need to add class names to specific checkboxes for javascript purposes. Is there a way to do that? -- Hector Why not navigate the dom with javascript? jQuery makes this very easy. - pw
[fw-general] Zend_Form - Adding CSS classnames to multiCheckbox inputs
Hello, I am building a form that uses the multiCheckbox form element. I need to add class names to specific checkboxes for javascript purposes. Is there a way to do that? I tried this, but it ended up adding the class name foo to all of the checkboxes: $this-addElement('multiCheckbox', 'publishers', array( 'label'= 'Publishers', 'multiOptions' = array(/* ... */), 'attribs' = array( 'class' = 'foo' ) )); I thought maybe I could pass in an associative array of value = classname but that ended up adding all of the class names to all of the checkboxes: $this-addElement('multiCheckbox', 'publishers', array( 'label'= 'Publishers', 'multiOptions' = array(/* ... */), 'attribs' = array( 'class' = array( 1 = 'foo', 7 = 'bar' ) ) )); I've also tried adding it to the label, but the result was the same (all class names were added to all labels) $this-addElement('multiCheckbox', 'publishers', array( 'label'= 'Publishers', 'multiOptions' = array(/* ... */), 'attribs' = array( 'label_class' = array( 1 = 'foo', 7 = 'bar' ) ) )); Any ideas on how to accomplish this? I wouldn't mind adding the classname to the label if necessary. Thanks! -- Hector
Re: [fw-general] Zend_Form and square brackets in elements' name
Julien Huang wrote: If obtain this : input name=question42[] value=0 / While I want this : input name=question[42][] value=0 / -- Julien Huang It is very useful to be able to use this syntax I agree. There are areas where Zend Framework is over engineered and unfortunately forms is one of them. In this case I would drop back to processing the elements without Zend Form's help. -- View this message in context: http://www.nabble.com/Zend_Form-and-square-brackets-in-elements%27-name-tp20483297p24866654.html Sent from the Zend Framework mailing list archive at Nabble.com.
[fw-general] Zend_Form: Adding elements to an existing display group
Hello, I am having some trouble with Zend_Form and display groups (ZF 1.8.2). I want to add an existing form element to an existing display group within the same form, but when I call $displayGroup-addElement($element), the element is re-added to the form, causing it to be rendered twice (once in the display group, and again outside of the display group). Here is my code (trimmed for clarity): class MyForm extends Zend_Form { public function init() { /* ... */ } public function addStandard(Standard $standard) { $name = 'standard_' . $standard-getId(); $this-addElement('checkbox', $name); $displayGroup = $this-getDisplayGroup('standards'); $displayGroup-addElement($this-getElement($name)); } } I have also tried just specifying the element's name, but that ends up in a fatal error: Call to a member function getName() on a non-object in /usr/share/pear/Zend/Form/DisplayGroup.php on line 433 I also noticed that I cannot create a display group without adding elements to it: $this-addDisplayGroup(array(), 'standards'); // throws exception No valid elements specified for display group This makes it difficult to create empty display groups as containers for the elements to be added later. I can get around this by creating the display group automatically when the first standard is added, but I am stumped on how to add the next standard to the existing display group. -- Hector
[fw-general] Zend_Form with elements having array names
Hi all, I'm up against something that has me stumped (not too hard to do ;) In html it is possible to name form elements with array names. For example, if I wanted a collection of an arbitrary number of elements such as favorite colors I could create elements like: input name='colors[]' / and the submitted form would contain an array of colors. I looked at Zend_Form_Elements_Multi and descendants but that seems geared to radio/checkbox/select elements. Anybody else had to deal with this? Sure would appreciate ideas or examples. If it were definable within a .ini type config file that would be the best of all possible worlds. Thanks in advance, Mike Wright
Re: [fw-general] Zend_Form with elements having array names
Do you need multiple text inputs that post as an array? You could create a multiText form element that extends Zend_Form_Element_Multi. Take a look at Zend_Form_Element_MultiRadio to see how it works. Yesterday I had to create a series of checkboxes that were built to look like a navigation tree (nested unordered lists). Extending Zend_Form_Element_Multi and creating a new view helper to handle it was a nice way to make it reusable. -- Hector On Wed, Jul 29, 2009 at 10:24 AM, Mike Wright mike.wri...@mailinator.comwrote: Hi all, I'm up against something that has me stumped (not too hard to do ;) In html it is possible to name form elements with array names. For example, if I wanted a collection of an arbitrary number of elements such as favorite colors I could create elements like: input name='colors[]' / and the submitted form would contain an array of colors. I looked at Zend_Form_Elements_Multi and descendants but that seems geared to radio/checkbox/select elements. Anybody else had to deal with this? Sure would appreciate ideas or examples. If it were definable within a .ini type config file that would be the best of all possible worlds. Thanks in advance, Mike Wright
Re: [fw-general] Zend_Form and Date validator
Try extending the validation class and override the $_messageTemplate variable. class My_Validate_NotEmpty extends Zend_Validate_NotEmpty { protected $_messageTemplates = array( parent::IS_EMPTY = It can't be empty!, ); } Then add the class prefix and path to the form so the messages in your extended classes can be found. class My_Form extends Zend_Form { public function __construct($options = null) { $this-addElementPrefixPath('My_Validate', APPLICATION_PATH . '/My/Validate', 'validate'); parent::__construct($options); } } holografix wrote: Hi I have a form with a text element and that I want to be validated as a date. $date = new Zend_Form_Element_Text('Date'); $date-setLabel('Date') -addValidator( 'Date', true, array( 'messages' = array( 'dateInvalidDate' = 'Opsss! Invalid date!', 'dateNot-MM-DD' = 'Opsss! Should enter a date!' ) ) ) -addValidator('NotEmpty', true, array('messages' = array('isEmpty' = 'It can't be empty!'))) -setRequired(true); If I leave date empty, $form-getMessages() says [Date] = Array ( [dateNot-MM-DD] = Opsss! Should enter a date! ) If I remove the NotEmpty validator it shows: [Date] = Array ( [isEmpty] = Value is required and can't be empty // not the message I expect: It can't be empty ) But if I add 'isEmpty' to the messages array in the first validator It throws an exception. Fatal error: Uncaught exception 'Zend_Validate_Exception' with message 'No message template exists for key 'isEmpty'' in C:\wwwroot\lib\php\ZendFramework\library\Zend\Validate\Abstract.php:149 ... What could be happening here? Cheers holo -- View this message in context: http://www.nabble.com/Zend_Form-and-Date-validator-tp24683825p24703649.html Sent from the Zend Framework mailing list archive at Nabble.com.