0
지금 zend framework 2에서 간단한 폼을 검증하려고했습니다. 이 항목을 고려하여 설명서와 많은 게시물을 확인했지만 해결 방법을 찾지 못했습니다. ZF2 간단한 폼 유효성 확인
나는 아주 간단한 양식을 가지고namespace Application\Form;
use Zend\InputFilter\InputFilter;
class AlimentInputFilter extends InputFilter {
public function init()
{
$this->add([
'name' => AlimentForm::year,
'required' => true,
'validators' => array(
array(
'name' => 'Between',
'options' => array(
'min' => 1900,
'max' => 3000,
),
),
),
]);
}
}
그리고 마지막으로 내 컨트롤러에서 나는 양식을
public function alimentAction(){
$form = new AlimentForm();
$form->setInputFilter(new AlimentInputFilter());
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$year = $form->get('year')->getValue();
$number = $form->get('number')->getValue();
return array('result' => array(
"msg" => "In the Year ".$year." you get ".$number." Points"
));
}
}
return array('form' => $form);
}
이 유효성을 검사 할 : 나는 정의 InputFilter를 만들어
class AlimentForm extends Form
{
public function __construct($name = null)
{
parent::__construct('aliment');
$this->add(array(
'required'=>true,
'name' => 'year',
'type' => 'Text',
'options' => array(
'label' => 'Jahr',
),
));
$this->add(array(
'required'=>true,
'name' => 'number',
'type' => 'Text',
'options' => array(
'label' => 'Number',
),
));
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
그렇게 어렵지는 않을 것입니다. 그러나 그물에서 발견 된 형태를 검증하는 모든 다른 방법들로부터, 저는 약간 혼란 스럽습니다. 에드 ...
내가 무엇이 누락 되었습니까?
안녕하세요. 미리 감사드립니다. 미국.