PHP代碼:Zend_Form和與Zend_Filter_StringTrim來setElementFilters不修剪
$form = new Zend_Form();
$filters = array(new Zend_Filter_StringTrim());
$form->setElementFilters($filters); // <-- ISSUE
$customerName = new Zend_Form_Element_Text('customer_name');
$customerName->setRequired();
$form->addElement($customerName);
$data = $this->_getAllParams();
if ($form->isValid($data)) {
var_dump($form->getValue('customer_name'));
// Should be "Testing Trim"
// Actual result is " Testing Trim "
} else {
exit('Failed');
}
HTML代碼:
<form action="" method="post">
<input type="text" name="customer_name" value=" Testing Trim " />
<input type="submit" />
</form>
有沒有人碰到這個問題,如果是的話,你如何解決它globaly的setElementFilters方法?
如果我將過濾器添加到元素,它工作正常。我只是不想爲每個元素設置修剪。
謝謝Vika。這工作。你會認爲這不重要。 – 2011-01-12 16:34:57