Zend Framework 2 : Create Simple Upload Form with File Validation

Welcome to Abdul Malik Ikhsan's Blog

Zend Framework 2 has ZendFileTransfer component that can provide file transfer need for our application. We can add Files validator and pass error message to ZendForm component object, that can be retrieve by view if process was failed. We can add another validator instead of Upload validator that registered by default in Http Adapter.


For example, i have upload form like this :


The code form will be like the following :

By that code above, we can call ProfileForm from action Controller :

For view, we can write the following :

Just that, and form will be created. How we filter the input ? we can create input filter by following :

Now, we can set inputFilter to form from action controller, pass data post and file to form object, and check the validation :

If form is valid, we can save file to directory we desired by ZendFileTransferAdapterHttp…

View original post 57 more words

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s