zend_form isValid总是假的

时间:2014-04-23 16:09:36

标签: zend-framework zend-form

我为使用Zend 1的网站编写代码。 我想在zend中重写旧的管理界面,但我的表单无法验证。

我将在此处发布表单,验证代码和调试输出。

形式:

class Form_Admin_Address_Neu extends Zend_Form {

public function init() {
$this->setMethod('post');

$this->addElement('text', '_street', array(
    'label' => 'Strasse:',
    'size' => 60,
    'required' => true,
    'filters' => array('StringTrim'),
));

$this->addElement('text', '_zip', array(
    'label' => 'PLZ:',
    'size' => 6,
    'required' => true,
    'filters' => array('StringTrim'),
));

$this->addElement('text', '_city', array(
    'label' => 'Stadt:',
    'required' => true,
    'size' => 30,
    'filters' => array('StringTrim'),
));

$this->addElement('text', '_lat', array(
    'label' => 'Latitude:',
    'required' => true,
    'size' => 30,
    'validators' => array('Float'),
    'filters' => array('Stringtrim'),
));

$this->addElement('text', '_lng', array(
    'label' => 'Longitude:',
    'required' => true,
    'size' => 30,
    'validators' => array('Float'),
    'filters' => array('Stringtrim'),
));

$this->addElement('checkbox', '_hidden', array(
    'label' => 'Hidden:',
    'size' => 1,
    'filters' => array('Int', 'Null'),
));

$this->addElement('submit', 'submit', array(
    'ignore' => true,
    'label' => 'Senden',
));

$this->addElement('hash', 'csrf', array(
    'ignore' => true,
));

$this->setAction('/admin/address/list');
}

}

其他字段(我只是在这里发布1,第二个就是这样):

class Form_Admin_Elements_CountrySelect extends Zend_Form_Element_Select {
public function init() {
$countrymapper = new Mapper_Country();
    $this->addMultiOption(0, 'Please select...');
    foreach ($countrymapper->fetchAll() as $country) {
        $this->addMultiOption($country->getId(), $country->getName());
    }
$this->setLabel("Land:");
}
}

代码:

$addForm = new Form_Admin_Address_Neu();
$regionselect = new Form_Admin_Elements_RegionSelect('region_id');
$regionselect->setRequired(true);
$addForm->addElement($regionselect);
$countryselect = new Form_Admin_Elements_CountrySelect('country_id');
$countryselect->setRequired(true);
$addForm->addElement($countryselect);

if ($addForm->isValid($_POST)) {
...
} else {
print_r($_POST);
print_r($addForm->getErrorMessages());
print_r($addForm->getCustomMessages());
print_r($addForm->getErrors());
}

输出:

Array
(
[_street] => sdvdsvsv
[_zip] => 111111
[_city] => sdfgsf
[_lat] => 1.0
[_lng] => 2.1
[_hidden] => 0
[country_id] => 1
[region_id] => 3
[submit] => Senden
[csrf] => d18dfed9d26e28d7a52aa4983b00667e
)
Array
(
)
Array
(
)
Array
(
[_street] => Array
    (
    )

[_zip] => Array
    (
    )

[_city] => Array
    (
    )

[_lat] => Array
    (
        [0] => notFloat
    )

[_lng] => Array
    (
        [0] => notFloat
    )

[_hidden] => Array
    (
    )

[submit] => Array
    (
    )

[csrf] => Array
    (
    )

[region_id] => Array
    (
    )

[country_id] => Array
    (
    )

)

在我看来,验证失败了,但我不知道为什么。 值存在于$ _POST中,但表单不验证。 我甚至尝试使用isValidPartial(),但结果相同。 我认为我做的事情根本就是错误的。 提示会很棒。

事先提前

1 个答案:

答案 0 :(得分:0)

尝试在commapoint中输入Latitude而不是Longitude
1,02,1代替1.02.1

我认为这是验证者Locale的问题