views:

239

answers:

4

Hi there,

I'm using the PHP Zend Framework.

How can I get the values from the controller sent by:

$infoForm=array(
// I get these values from a DB 'idCity' => $idCity , 'idRestaurant'=>$idRestaurant

);

$form->populate($infoForm);

i get the info in the Dojo_Form

$city = new Zend_Dojo_Form_Element_FilteringSelect('idCity');

but by idCity i'm going to the DB and update the FilteringSelect('idRestaurant') to see the restaurants in that City

How can I see the value of the variables sent by $form->populate($infoForm); in the form?

I've tried $this->getvalue('idCity') in the form, but this seems to get the value only when it returns to the controller. I want to check the value idCity and then generate the FilteringSelect('idRestaurant').

::Explaining better

I've got: I've got: Controller (extends Zend_Controller_Action)

Model (Zend_Db_Table_Abstract) -> functions to access database

Form (extends Zend_Dojo_Form) -> create the from :: I want to see the values here!!

View (where I can view the form)

I get the values from the database in the controller, then I send them to Form with $form->populate($infoForm); I woul like to see the values that came from the controller to generate the form accordingly

A: 

You can set $this->view->varName to feed back the value so that the form can see it.

For example, in the controller (action):

$this->view->myVar = $this->getRequest()->getParam['myVar'];

Then in the form just ask for:

<?= $this->myVar ?>
Arthur Frankel
Thats when I'm trying to pass the variables from the controller to the view!I'll try to explain better.I've got: I've got: Controller (extends Zend_Controller_Action) Model (Zend_Db_Table_Abstract) -> functions to access databaseForm (extends Zend_Dojo_Form) -> create the from :: I want to see the values here!! View (where I can view the form)I get the values from the database in the controller, then I send them to Form with $form->populate($infoForm);I woul like to see the values that came from the controller to generate the form accordingly
Carlos
I haven't worked with Zend_Dojo_Form but I assume it's either via the request (since that should still be around), or passing a custom object with the values.
Arthur Frankel
A: 

You can get a forms' values like this:

$valueArray = $form->getValues();

Then $valueArray will be like:

array(
    'elementName1' => 'value1',
    'elementName2' => 'value2',
    ...
);

... But I may have misunderstood the question, if so, sorry!

berty
A: 

I'm not familiar with Zend_Dojo or even Dojo, but itself but after some research I think you should have a structure similar to this in your controller:

public function myAjaxAction()
{
    if ($this->getRequest()->isXmlHttpRequest()) // if this is an ajax request
    {
        $this->_helper->viewRenderer->setNoRender(); //ajax call, so do //not render
        $jsonData = *your data in json format that will be passed back to the form*
        $this->getResponse()->appendBody($jsonData); // _response is the Response object                                                //that you are appending data to
    }
}

The code above is a simplified version based on the link below. For more info see that site. Be aware that the version used is 1.6 but it can give you a better idea. SOURCE: http://blog.midstride.com/2008/08/26/integrating-ajaxdojo-into-the-zend-mvc-in-8-steps/

helloworlder
A: 

zend form elements should have an id atached to then when you add them to the form and you can use that to reference them in your case it should be:

$form->idCity->getvalue();
solomongaby