Zend3 InputFilter not validating Form
I've found another post (ZF2 InputFilter not validating fieldset) for my issue, but it doesn't helped.
I have a Category Entity and i want to validate the length of the title.
So my Model (without the existing getter and setter)
class Category
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $name;
My Form for the Category
:
class CategoryForm extends Form
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->setInputFilter(new CategoryFilter());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text'
]);
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
And the Filter which currently not working.
class CategoryFilter extends InputFilter
public function init()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And if someone needed my addAction in the Controller:
public function addAction()
$request = $this->getRequest();
if ($request->isPost())
$this->form->setData($request->getPost());
if ($this->form->isValid())
$this->mapper->save($this->form->getData());
$this->redirect()->toRoute('categories');
return [
'form' => $this->form
];
In every example which i found, it should be working. But my form is never validated nor filtered (with the trim).
Did i forget something? Why it doesn't work?
zend-framework zend-form zend-framework3 zend-filter
add a comment |
I've found another post (ZF2 InputFilter not validating fieldset) for my issue, but it doesn't helped.
I have a Category Entity and i want to validate the length of the title.
So my Model (without the existing getter and setter)
class Category
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $name;
My Form for the Category
:
class CategoryForm extends Form
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->setInputFilter(new CategoryFilter());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text'
]);
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
And the Filter which currently not working.
class CategoryFilter extends InputFilter
public function init()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And if someone needed my addAction in the Controller:
public function addAction()
$request = $this->getRequest();
if ($request->isPost())
$this->form->setData($request->getPost());
if ($this->form->isValid())
$this->mapper->save($this->form->getData());
$this->redirect()->toRoute('categories');
return [
'form' => $this->form
];
In every example which i found, it should be working. But my form is never validated nor filtered (with the trim).
Did i forget something? Why it doesn't work?
zend-framework zend-form zend-framework3 zend-filter
add a comment |
I've found another post (ZF2 InputFilter not validating fieldset) for my issue, but it doesn't helped.
I have a Category Entity and i want to validate the length of the title.
So my Model (without the existing getter and setter)
class Category
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $name;
My Form for the Category
:
class CategoryForm extends Form
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->setInputFilter(new CategoryFilter());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text'
]);
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
And the Filter which currently not working.
class CategoryFilter extends InputFilter
public function init()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And if someone needed my addAction in the Controller:
public function addAction()
$request = $this->getRequest();
if ($request->isPost())
$this->form->setData($request->getPost());
if ($this->form->isValid())
$this->mapper->save($this->form->getData());
$this->redirect()->toRoute('categories');
return [
'form' => $this->form
];
In every example which i found, it should be working. But my form is never validated nor filtered (with the trim).
Did i forget something? Why it doesn't work?
zend-framework zend-form zend-framework3 zend-filter
I've found another post (ZF2 InputFilter not validating fieldset) for my issue, but it doesn't helped.
I have a Category Entity and i want to validate the length of the title.
So my Model (without the existing getter and setter)
class Category
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $name;
My Form for the Category
:
class CategoryForm extends Form
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->setInputFilter(new CategoryFilter());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text'
]);
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
And the Filter which currently not working.
class CategoryFilter extends InputFilter
public function init()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And if someone needed my addAction in the Controller:
public function addAction()
$request = $this->getRequest();
if ($request->isPost())
$this->form->setData($request->getPost());
if ($this->form->isValid())
$this->mapper->save($this->form->getData());
$this->redirect()->toRoute('categories');
return [
'form' => $this->form
];
In every example which i found, it should be working. But my form is never validated nor filtered (with the trim).
Did i forget something? Why it doesn't work?
zend-framework zend-form zend-framework3 zend-filter
zend-framework zend-form zend-framework3 zend-filter
asked Nov 14 '18 at 8:58
robrob
1,32351526
1,32351526
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
So i've changed a little bit.
The Category Form goes to:
class CategoryForm extends Form
public function init()
$this->add(array(
'type' => CategoryFieldSet::class,
'options' => array(
'use_as_base_fieldset' => true,
),
));
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
I changed also the Filter
class CategoryFilter extends InputFilter
public function __construct()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And after this i defined the FieldSet with the validators:
class CategoryFieldSet extends Fieldset implements InputFilterProviderInterface
/**
*
*/
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text',
]);
/**
* Should return an array specification compatible with
* @link ZendInputFilterFactory::createInputFilter().
*
* @return array
*/
public function getInputFilterSpecification()
$filter = new CategoryFilter();
return $filter->getInputs();
After changing this i get the expected error message like:
The input is less than 5 characters long
Nicely done figuring that out thus far. Could go a bit further with removal ofInputFilterProviderInterface
if you like. Bit cleaner. Would require you to add to theCategoryForm
aCategoryFormInputFilter
with aCategoryFieldsetInputFilter
as a child. I created a repo a while back to help out with this. Also one for example implementation. Pay special attention to how to bind InputFilters to Input's in the Factory classes.
– rkeet
Nov 15 '18 at 7:45
@rkeet that looks quit better. i struggled with the fixed filter binding. i will rebuild my test application. many thanks for the hint
– rob
Nov 15 '18 at 8:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296302%2fzend3-inputfilter-not-validating-form%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So i've changed a little bit.
The Category Form goes to:
class CategoryForm extends Form
public function init()
$this->add(array(
'type' => CategoryFieldSet::class,
'options' => array(
'use_as_base_fieldset' => true,
),
));
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
I changed also the Filter
class CategoryFilter extends InputFilter
public function __construct()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And after this i defined the FieldSet with the validators:
class CategoryFieldSet extends Fieldset implements InputFilterProviderInterface
/**
*
*/
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text',
]);
/**
* Should return an array specification compatible with
* @link ZendInputFilterFactory::createInputFilter().
*
* @return array
*/
public function getInputFilterSpecification()
$filter = new CategoryFilter();
return $filter->getInputs();
After changing this i get the expected error message like:
The input is less than 5 characters long
Nicely done figuring that out thus far. Could go a bit further with removal ofInputFilterProviderInterface
if you like. Bit cleaner. Would require you to add to theCategoryForm
aCategoryFormInputFilter
with aCategoryFieldsetInputFilter
as a child. I created a repo a while back to help out with this. Also one for example implementation. Pay special attention to how to bind InputFilters to Input's in the Factory classes.
– rkeet
Nov 15 '18 at 7:45
@rkeet that looks quit better. i struggled with the fixed filter binding. i will rebuild my test application. many thanks for the hint
– rob
Nov 15 '18 at 8:31
add a comment |
So i've changed a little bit.
The Category Form goes to:
class CategoryForm extends Form
public function init()
$this->add(array(
'type' => CategoryFieldSet::class,
'options' => array(
'use_as_base_fieldset' => true,
),
));
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
I changed also the Filter
class CategoryFilter extends InputFilter
public function __construct()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And after this i defined the FieldSet with the validators:
class CategoryFieldSet extends Fieldset implements InputFilterProviderInterface
/**
*
*/
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text',
]);
/**
* Should return an array specification compatible with
* @link ZendInputFilterFactory::createInputFilter().
*
* @return array
*/
public function getInputFilterSpecification()
$filter = new CategoryFilter();
return $filter->getInputs();
After changing this i get the expected error message like:
The input is less than 5 characters long
Nicely done figuring that out thus far. Could go a bit further with removal ofInputFilterProviderInterface
if you like. Bit cleaner. Would require you to add to theCategoryForm
aCategoryFormInputFilter
with aCategoryFieldsetInputFilter
as a child. I created a repo a while back to help out with this. Also one for example implementation. Pay special attention to how to bind InputFilters to Input's in the Factory classes.
– rkeet
Nov 15 '18 at 7:45
@rkeet that looks quit better. i struggled with the fixed filter binding. i will rebuild my test application. many thanks for the hint
– rob
Nov 15 '18 at 8:31
add a comment |
So i've changed a little bit.
The Category Form goes to:
class CategoryForm extends Form
public function init()
$this->add(array(
'type' => CategoryFieldSet::class,
'options' => array(
'use_as_base_fieldset' => true,
),
));
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
I changed also the Filter
class CategoryFilter extends InputFilter
public function __construct()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And after this i defined the FieldSet with the validators:
class CategoryFieldSet extends Fieldset implements InputFilterProviderInterface
/**
*
*/
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text',
]);
/**
* Should return an array specification compatible with
* @link ZendInputFilterFactory::createInputFilter().
*
* @return array
*/
public function getInputFilterSpecification()
$filter = new CategoryFilter();
return $filter->getInputs();
After changing this i get the expected error message like:
The input is less than 5 characters long
So i've changed a little bit.
The Category Form goes to:
class CategoryForm extends Form
public function init()
$this->add(array(
'type' => CategoryFieldSet::class,
'options' => array(
'use_as_base_fieldset' => true,
),
));
$this->add([
'name' => 'submit',
'type' => 'submit'
]);
I changed also the Filter
class CategoryFilter extends InputFilter
public function __construct()
$this->add([
'name' => 'name',
'required' => true,
'filters' => [
['name' => StringTrim::class]
],
'validators' => [
[
'name' => StringLength::class,
'options' => [
'min' => 5
]
]
]
]);
And after this i defined the FieldSet with the validators:
class CategoryFieldSet extends Fieldset implements InputFilterProviderInterface
/**
*
*/
public function init()
$this->setHydrator(new ClassMethods(false));
$this->setObject(new Category());
$this->add([
'name' => 'id',
'type' => 'hidden'
]);
$this->add([
'name' => 'name',
'type' => 'text',
]);
/**
* Should return an array specification compatible with
* @link ZendInputFilterFactory::createInputFilter().
*
* @return array
*/
public function getInputFilterSpecification()
$filter = new CategoryFilter();
return $filter->getInputs();
After changing this i get the expected error message like:
The input is less than 5 characters long
answered Nov 14 '18 at 10:42
robrob
1,32351526
1,32351526
Nicely done figuring that out thus far. Could go a bit further with removal ofInputFilterProviderInterface
if you like. Bit cleaner. Would require you to add to theCategoryForm
aCategoryFormInputFilter
with aCategoryFieldsetInputFilter
as a child. I created a repo a while back to help out with this. Also one for example implementation. Pay special attention to how to bind InputFilters to Input's in the Factory classes.
– rkeet
Nov 15 '18 at 7:45
@rkeet that looks quit better. i struggled with the fixed filter binding. i will rebuild my test application. many thanks for the hint
– rob
Nov 15 '18 at 8:31
add a comment |
Nicely done figuring that out thus far. Could go a bit further with removal ofInputFilterProviderInterface
if you like. Bit cleaner. Would require you to add to theCategoryForm
aCategoryFormInputFilter
with aCategoryFieldsetInputFilter
as a child. I created a repo a while back to help out with this. Also one for example implementation. Pay special attention to how to bind InputFilters to Input's in the Factory classes.
– rkeet
Nov 15 '18 at 7:45
@rkeet that looks quit better. i struggled with the fixed filter binding. i will rebuild my test application. many thanks for the hint
– rob
Nov 15 '18 at 8:31
Nicely done figuring that out thus far. Could go a bit further with removal of
InputFilterProviderInterface
if you like. Bit cleaner. Would require you to add to the CategoryForm
a CategoryFormInputFilter
with a CategoryFieldsetInputFilter
as a child. I created a repo a while back to help out with this. Also one for example implementation. Pay special attention to how to bind InputFilters to Input's in the Factory classes.– rkeet
Nov 15 '18 at 7:45
Nicely done figuring that out thus far. Could go a bit further with removal of
InputFilterProviderInterface
if you like. Bit cleaner. Would require you to add to the CategoryForm
a CategoryFormInputFilter
with a CategoryFieldsetInputFilter
as a child. I created a repo a while back to help out with this. Also one for example implementation. Pay special attention to how to bind InputFilters to Input's in the Factory classes.– rkeet
Nov 15 '18 at 7:45
@rkeet that looks quit better. i struggled with the fixed filter binding. i will rebuild my test application. many thanks for the hint
– rob
Nov 15 '18 at 8:31
@rkeet that looks quit better. i struggled with the fixed filter binding. i will rebuild my test application. many thanks for the hint
– rob
Nov 15 '18 at 8:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296302%2fzend3-inputfilter-not-validating-form%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown