简体   繁体   English

Zend Framework 2 Form和InputFilter重新调整不同的值

[英]Zend Framework 2 Form and InputFilter retuning different values

I have a element(Select) of name, parameter . 我有一个名称为parameter的元素(选择)。 The problem is that on validation it returns error like this: 问题是在验证时它返回如下错误:

The input was not found in the haystack

I know that this is returned by InArray Validator. 我知道这是由InArray验证程序返回的。 But, how can this happen when the input is valid. 但是,当输入有效时如何发生呢? So, I tried to inspect the form element and inputfilter. 因此,我尝试检查表单元素和inputfilter。 So, i did: 所以我做了:

print_r($form->get('parameter')->getValue()); // returns frequency  
print_r($form->getInputFilter()->get('parameter')->getValue()); // returns 0

I just cant understand, why are they returning different values? 我无法理解,为什么它们返回不同的值?

Here is the full code: 这是完整的代码:

$postData = $request->getPost()->toArray();

$form->setData($postData);

print_r($form->get('parameter')->getValue());

if ($form->isValid()) {
    $alarm->exchangeArray($form->getData());
    $this->getAlarmMapper()->save($alarm);
    $changesSaved = true;
}
print_r($form->getInputFilter()->get('parameter')->getValue());

据我所知,如果验证失败,则过滤器根本不会返回值,这就是它返回0的原因。因此,您可能应该查看验证内部,为什么它无法验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM