Ankur Mukherjee
Ankur Mukherjee

Reputation: 3867

Php form in Zend Framework

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

Upvotes: 0

Views: 444

Answers (5)

tasmaniski
tasmaniski

Reputation: 4898

This helped me a lot At the beginning:

http://www.zendcasts.com/zend_form-introduction-part-1/2009/02/

http://www.zendcasts.com/zend_form-introduction-part-2/2009/02/

You should use Zend Form (not PHP form), it should be standard except in some special cases.

Upvotes: 1

Benjamin Cremer
Benjamin Cremer

Reputation: 4822

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

Upvotes: 0

Ronn0
Ronn0

Reputation: 2269

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();

Upvotes: 2

Iznogood
Iznogood

Reputation: 12853

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.

Upvotes: 1

Pekka
Pekka

Reputation: 449823

See e.g.

Upvotes: 1

Related Questions