무슨 일이 일어나는지 잘 모르겠습니다. 다중 선택 필드와 함께 Zend Form 2를 사용하고 있습니다. 코드를 제출하면 가치가 게시됩니다. zend 양식 2를 통해 값을 실행할 때 유효성 검사 오류가 발생하지만 multiselect 필드가 갑자기 비어 있습니다.젠드 양식 2 유효성 검사 후 다중 선택 필드가 비어 있습니다.
class Form extends \Zend\Form\Form
{
// input filter to set up filters and validators
protected $myInputFilter;
public function __construct()
{
// create the zend form
parent::__construct();
// make it a bootstrap form
$this->setAttribute('class', 'form-horizontal');
$this->setAttribute('role', 'form');
// set the default objects we'll use to build the form validator
$this->myInputFilter = new \Zend\InputFilter\InputFilter();
}
}
class AddPublicationForm extends Form
{
public function __construct()
{
// create the zend form
parent::__construct();
$this->setAttribute('class', 'form-horizontal');
$this->setAttribute('id', 'add-publication-form');
$this->add([
'name' => 'author[]',
'attributes' => [
'class' => 'form-control',
'data-placeholder' => 'Author',
'multiple' => 'multiple',
'placeholder' => 'Author',
],
'required' => false,
'type' => \Zend\Form\Element\Select::class,
'options' => [
'value_options' => [
'check1' => 'check1',
'check2' => 'check2',
],
],
]);
$this->myInputFilter->add([
'filters' => [],
'name' => 'author[]',
'required' => false,
'validators' => [],
]);
// attach validators and filters
$this->setInputFilter($this->myInputFilter);
// prepare the form
$this->prepare();
}
}
다음은 내가 사용중인 젠드 양식 개체입니다. 슬림 프레임 워크 2를 백엔드로 사용하고 있습니다. 다음은 컨트롤러 객체입니다
public function addAction()
{
$request = $this->app->request;
$form = new Form\AddPublicationForm();
if ($request->isPost()) {
$params = $request->params();
// DUMP 1: exit('<pre>'.print_r($params, true).'</pre>');
$form->setData($params);
if ($form->isValid()) {
$data = $form->getData();
// DUMP 2: exit('<pre>'.print_r($data, true).'</pre>');
}
}
}
DUMP 1 :
Array
(
[author] => Array
(
[0] => check1
[1] => check2
)
}
DUMP 2 :
Array
(
[author[]] =>
)
내가 아니에요 때문에 난 그냥 여기에 검증을 우회 아주 쉽게 할 수 실현 해당 필드의 유효성 검사기를 사용합니다. 나는 근본적인 원인에 더 관여한다.
유효성이 검사 된 저자 데이터가 비어있는 이유는 무엇입니까?
이것은 작동합니다! 감사! – lokisapocalypse