# Form input filter

**URL:** <https://discourse.laminas.dev/t/form-input-filter/437>\
**Category:** Components & MVC\
**Tags:** zend-form\
**Created:** [January 18, 2018, 3:51pm UTC](https://discourse.laminas.dev/t/form-input-filter/437 "2018-01-18T15:51:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![erfan](https://avatars.discourse-cdn.com/v4/letter/e/c4cdca/32.png) [@erfan](https://discourse.laminas.dev/u/erfan)\
**Post date:** [January 18, 2018, 3:51pm UTC](https://discourse.laminas.dev/t/form-input-filter/437/1 "2018-01-18T15:51:08Z")

</div>

hi there, here i have the form model’s element definition like this:

```
class ContactForm extends Form
{
public function __construct($name = null)
{
    parent::__construct('contactform');
    $this->setAttribute('method','POST');
    $this->addElements();
    $this->addInputFilter();
}
private function addElements()
{
    $this->add([
        'type'=>'text',
        'name'=>'fname',
        'attributes'=>
            [
                'placeholder'=>'firstname',
                'class'=>'form-control',
            ]

    ]);
 }
   private function addInputFilter()
{
    $inputfilter = new InputFilter();
    $this->setInputFilter($inputfilter);
    $inputfilter->add([
        'name'=>'fname',
        'required'=>true,
        'filters'=>
            [
                ['name'=>'StripTags'],
                ['name'=>'StringTrim'],
            ],
        'validators'=>
            [
                [
                    'name'=>'StringLength',
                    'options'=>
                        [
                            'encoding'=>'UTF-8',
                            'min'=>1,
                            'max'=>20,
                        ],

                ],
            ],
    ]);
     }
    }

```

i got all other things prepared like Controller and View.  
the problem is when I try submit this form with bunch of numbers instead of strings and in my surprise there is no filter or validation error in return and the form is submitted despite using  
`'type' => 'text'`  
inside my field definition.  
what am I to do now?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [January 18, 2018, 4:58pm UTC](https://discourse.laminas.dev/t/form-input-filter/437/2 "2018-01-18T16:58:31Z")

</div>

> [@erfan](#):
>
> in my surprise there is no filter or validation error in return and the form is submitted despite using ‘type’ =\> ‘text’ inside my field definition.

The type option only sets the type for the [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text) in HTML and use the related zend-form element. This has nothing to do with a data type or which data type is accepted.  
If you use the form element `number`, then you will get also a string. You must filter the value. (See: [`Zend\Filter\ToInt`](https://docs.zendframework.com/zend-filter/standard-filters/#toint))  
This is not a special behaviour of the ZF, this is the normal behaviour in HTTP und PHP.
