views:

53

answers:

4

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

+1  A: 

See e.g.

Pekka
I don't want to use the zend_form but i wish to use the simple html form.How to do this
Ankur Mukherjee
@Ankhur Why not simply output some form HTML then? What do you need the Zend Framework for at all?
Pekka
Means without using zend form ,you are saying that it will be somewhat not using the zend framework properly and actually wasting it
Ankur Mukherjee
@Ankur not necessarily, but your question doesn't make much sense yet to me. What do you mean by a "simple form"? I think you need to explain in more detail what you are doing with the Framework and what exactly your question is.
Pekka
I am using the zend framework in the usual prescribed manner but i want to use simple html form in place of zend form.So i wish to know how to integrate this form with the zend framework
Ankur Mukherjee
@Ankur Sorry, I don't know enough about ZF's MVC concept to answer that. I suppose, though, that you would integrate it just like any other piece of HTML.
Pekka
But the usual zend form validation and other methods will they work in the usual manner?
Ankur Mukherjee
@Ankur I don't know, sorry! I doubt that they will work as usual without some tweaking, though.
Pekka
You can't use Zend Form to validate the form if you aren't using Zend Form. You can however use Zend_Validate components (which Zend Form uses anyway), so I would suggest you check those pages in the manual, that should give you a good start.
Tim Fountain
A: 

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.

Iznogood
+1  A: 

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();
Ronn0
A: 

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
Benjamin Cremer