How can i use a simple php form in zend framework.
I am new to this framework,so please explain in detail.
Thanks in advance
How can i use a simple php form in zend framework.
I am new to this framework,so please explain in detail.
Thanks in advance
See e.g.
Zend Form Quick start at the official Zend Framework documentation
Simple Zend Form Example from Rob Allen's Blog
Just create your form like you would normally but in your view file (index.phtml for example).
It will work. Nothing special to do just open a <form>
tag and start coding.
You can use normal HTML forms. Some code snippets for your controller:
// Get all params (Notice: including URL params)
$this->getRequest()->getParams();
// Get single param
$this->getRequest()->getParam('paramName');
// Check if post
$this->getRequest()->isPost();
If you really want to use plain html forms you should at least consider Zend_Filter_Input for filtering/validation the userinput.
$filters = array('body' => array('StringTrim' , 'StripTags'));
$validators = array('body' => 'Alpha');
if (!$this->getRequest()->isPost()) {
// display form;
return;
}
$input = new Zend_Filter_Input($filters, $validators, $this->getRequest()->getParams());
if (!$input->isValid()) {
// failed validation
$this->view->messages = $input->getMessages();
// redisplay form and show error messages
return;
}
// form is valid, values are filtered
echo $input->body