Zend 表单验证不起作用可能是由于多种原因导致的。以下是一些建议和可能的解决方案:
composer install
或 composer update
命令。$inputFilter = new InputFilter();
$inputFilter->add([
'name' => 'username',
'required' => true,
'filters' => [
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => 'StringLength',
'options' => [
'min' => 6,
'max' => 255,
],
],
],
]);
$form = new Form();
$form->setInputFilter($inputFilter);
public function submitAction()
{
$form = new Form();
$form->setInputFilter($inputFilter);
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
// 处理表单数据
}
}
return new ViewModel([
'form' => $form,
]);
}
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('submit'));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('csrf'));
echo $this->formRow($form->get('username'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
如果以上建议仍然无法解决问题,请提供更多关于问题的详细信息,以便更好地帮助您解决问题。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云