Hi,
I'm sorry to bring this up again but I'm really surprised there's been no
reply regarding this problem yet.
Can anyone confirm if it's a real issue, in which case I'll open a ticket,
or if it's now the desired behavior of Zend_Validate_NotEmpty for null
values?
Martin Carpentier
On Tue, Sep 8, 2009 at 10:30, Martin Carpentier wrote:
> Hi again,
>
> Just following up on the issue I previously described to see if someone can
> confirm the issue and to see if there's a different(better) solution for it.
> It's a problem that need to be solved before I can upgrade our application
> to 1.9.x because it messes with our custom error messages and translations.
>
> Thank you in advance for your help.
>
> Martin Carpentier
>
>
>
> On Thu, Sep 3, 2009 at 17:19, Martin Carpentier <
> carpentier.mar...@gmail.com> wrote:
>
>> Hi,
>>
>> since the modification made to Zend_Validate_NotEmpty in ZF 1.9.0
>> (checking the value for valid types) radio buttons set with the required
>> flags don't return the proper error message if submitted without any of its
>> options checked.
>>
>> here's a simple example to recreate the problem:
>>
>> // in a TestController
>> public function testAction()
>> {
>> $request = $this->getRequest();
>>
>> $form = new Zend_Form();
>> $form->setAction('/test/test')
>> ->setName('formTest')
>> ;
>>
>> $options = array(
>> 'no'=> 'no',
>> 'yes' => 'yes',
>> );
>>
>> $form->addElement('Radio', 'testRadio', array(
>> 'label'=> "test ?",
>> 'required' => true,
>> 'multiOptions' => $options,
>> ));
>>
>> $form->addElement('Submit', 'suivant', array(
>> 'required' => false,
>> 'ignore' => true,
>> 'label'=> 'submit test',
>> ));
>>
>> if ($this->getRequest()->isPost()) {
>> if ($form->isValid($request->getPost())) {
>> Zend_Debug::dump($form);
>> }
>> }
>>
>> $this->view->form = $form;
>> }
>>
>> Now, when submitting the form without selecting any option, we get the
>> invalid message: "Invalid type given, value should be float, string, or
>> integer"
>> Before 1.9.0 we would get the correct and expected message: "Value is
>> required and can't be empty"
>>
>> The problem is caused by the addition of those lines in
>> Zend_Validate_NotEmpty:
>>
>> if (!is_string($value) && !is_int($value) && !is_float($value) &&
>> !is_bool($value)) {
>> $this->_error(self::INVALID);
>> return false;
>> }
>>
>> With that check in place, a null $value would get flagged as being of an
>> INVALID type
>> A fix would be to check also that the value is not null like this:
>>
>> if (null !== $value && !is_string($value) && !is_int($value) &&
>> !is_float($value) && !is_bool($value)) {
>> $this->_error(self::INVALID);
>> return false;
>> }
>>
>> Let me know if I should submit a bug report... or if I shouldn't be
>> expecting that behavior anymore.
>>
>> Martin Carpentier
>>
>
>