Zend Framework

Zend_Form::getValidValues(): dont't return values for ignored elements

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.10.5
  • Fix Version/s: 1.10.6
  • Component/s: Zend_Form
  • Labels:
    None

Description

<?php
$form = new Zend_Form();
$form->addElement(new Zend_Form_Element_Text('integer', array(
'label' => 'Integer value',
'required' => true,
'filters' => array('Int'),
'validators'=> array(
array('GreaterThan', false, array('min' => 0))
)
)));

$form->addElement(new Zend_Form_Element_Submit('submit', array(
'label' => 'Submit form',
'required'=> false,
'ignore'=> true
)));

$validValues = $form->getValidValues(array(
'integer' => '2z',
'submit' => 'Submit form'
));
?>

expect:
Array
(
[integer] => 2
)
but got:
Array
(
[integer] => 2
[submit] => Submit form
)

Activity

Hide
Christian Albrecht added a comment -

Implemented in trunk r22309 and merged into 1.10 release

Show
Christian Albrecht added a comment - Implemented in trunk r22309 and merged into 1.10 release
Hide
Matthew Weier O'Phinney added a comment -

Actually, Christian, please revert the patch.

When an element is marked as "ignore", the intention is that getValues() and getValidValues() should not return that element – that's the whole purpose of the "ignore" flag in the first place. The idea is that for elements that have no purpose in your model – such as submit and reset buttons – you can flag them as "ignore" so that the values will not be aggregated.

If you want the value, simply don't flag it to "ignore".

Show
Matthew Weier O'Phinney added a comment - Actually, Christian, please revert the patch. When an element is marked as "ignore", the intention is that getValues() and getValidValues() should not return that element – that's the whole purpose of the "ignore" flag in the first place. The idea is that for elements that have no purpose in your model – such as submit and reset buttons – you can flag them as "ignore" so that the values will not be aggregated. If you want the value, simply don't flag it to "ignore".
Hide
Alexey Pakhomov added a comment -

Yes, Matthew. Exactly same behavior I expect. But in recent release "ignore" flag is ignored. As I can see in trunk this was fixed with checking for

if (!$element->getIgnore()) { ... }

Show
Alexey Pakhomov added a comment - Yes, Matthew. Exactly same behavior I expect. But in recent release "ignore" flag is ignored. As I can see in trunk this was fixed with checking for if (!$element->getIgnore()) { ... }
Hide
Christian Albrecht added a comment -

Matthew, maybe that was due to my not so perfect english - the commit message was
make ... not collect ...

This functionality was either lost somewhere at the bughunt in april, or wasn't
implemented in getValidValues() before.

So now after the patch applied the behaviour is exactly what you want it to be

Show
Christian Albrecht added a comment - Matthew, maybe that was due to my not so perfect english - the commit message was make ... not collect ... This functionality was either lost somewhere at the bughunt in april, or wasn't implemented in getValidValues() before. So now after the patch applied the behaviour is exactly what you want it to be
Hide
Matthew Weier O'Phinney added a comment -

Christian – awesome! Yeah, the verbiage had me confused, so I wanted to double-check.

Show
Matthew Weier O'Phinney added a comment - Christian – awesome! Yeah, the verbiage had me confused, so I wanted to double-check.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: