Sadee
Sadee

Reputation: 3180

Can I use my normal (html) form in Zend Framework?

Can I use my normal (html) form in Zend Framework ? How can I do that & How can I call action in IndexController file?

Upvotes: 2

Views: 2066

Answers (5)

Samer Hannoun
Samer Hannoun

Reputation: 1

Just to know this is not a good practice to implement, but to solve such problem do the following: in the view file when you define the form

    <form action = "<?php echo $this->url(array('action'=>'ACTIONAME')); ?>" ...>
................
</form> 

in the corresponding action name

 if($this->_request->isPost()){
        foreach ($_POST as $var => $value) { 
        echo "$var = $value<br>"; 
        } 

Upvotes: 0

Hanseh
Hanseh

Reputation: 717

Yes, definitely.. You just have to remove the isValid call in your controller since it won't be performing any validation and also remove the post request check if it will not contain any form. It's like creating a common view with simple links in it.

Upvotes: 1

Sadee
Sadee

Reputation: 3180

Yes, I have a module called 'contact', and an action addcontactAction() in the ContactController.php.

So I can use : /view/scripts/contacts/addcontact.phtml

<form  action="" method="post" name="frm_addcontact" />
<input name="cn_fname" type="text" class="textbox" id="cn_fname"/>
<input type="submit" class="button" id="save" value="Save" />
</form>

when this form is submitted, it calls addcontactAction() in the controller.

$cn_fname       = $_REQUEST['cn_fname']; 

Upvotes: 0

homelessDevOps
homelessDevOps

Reputation: 20726

thats no problem, put your form code inside the view script for the associated action. Maybe:

formAction() 
{
   // check if post request
   if ($this->getRequest()->isPost()) {       
       // read global $_POST array
       $data = $this->getRequest()->getPost();
   }
}

the associated view ist than form.phtml

Upvotes: 1

roman
roman

Reputation: 11278

of course you can ... just use

<form action="/index/action" methode="POST">

to access post arguments use

$this->getRequest()->getParam('argument')

Upvotes: 2

Related Questions