views:

418

answers:

1

I'm having trouble with zend framework's string trim filter. I use the following code to set up a text element in a Zend_Form:

$voucherValidator = new Project_Validate_Voucher();        
$code = $this->addElement('text', 'code', array('label'=>'Gutscheincode'));
$code = $this->getElement('code')
    ->addFilter('StringTrim')
    ->addValidator($voucherValidator, true);

When I type in some text with preceeding blanks or tabs, the validator correctly works on the StringTrim filtered input and accepts the input. When I later check the $_POST['code'] after code submission, I get the unfiltered input. How can I get my text element to post the filtered value?

+4  A: 

Use $code = $this->code->getValue() as Zend_Form doesn't actually filter the $_POST array.

smack0007
Awesome, this works :). Btw, I found out that I can also use $this->getValue('code'). Thanks a lot
Wunibald
You can also use this getValues() and that will return the whole form filtered.
smack0007