[英]Get input value in view Zend Framework 2
I created a form input 我创建了一个表单输入
$this->add(array( 'name' => 'submit', 'attributes' => array( 'type' => 'submit', 'value' => 'UserRestorePassword.Restore', 'id' => 'submitbutton', 'class' => 'btn btn-primary btn-sm', 'style' => 'padding: 7px 35px;' ), ));
And this generates: 这会生成:
<input name="submit" type="submit" id="submitbutton" class="btn btn-primary btn-sm" style="padding: 7px 35px;" value="Restore">
In view: 鉴于:
<?=$this->translate($this->formSubmit($form->get('submit')));?>
How to get Restore
value from this form? 如何从此表单中获取
Restore
值?
如果你只想value
的属性submit
元素,调用getValue
该元素的方法
$value = $form->get('submit')->getValue(); // = UserRestorePassword.Restore
from https://stackoverflow.com/a/12367718/468891 : 来自https://stackoverflow.com/a/12367718/468891 :
If you need the value from the form which has been assigned previously, you can access it using
如果您需要以前分配的表单中的值,则可以使用
$form->get('elementName')->getValue();
$ form-> get('elementName')-> getValue(); However, if you're using InputFilters, you need to fetch it using
但是,如果您使用的是InputFilters,则需要使用
$form->getInputFilter()->getValue('name');
$ form-> getInputFilter()-> getValue('name');
Otherwise, the value you're retrieving was not passed through the filters.
否则,您要检索的值不会通过过滤器传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.