0
votes

I want to get all values of combobox not only selected value.
example:

$price = array('100','200','300');
echo $this->form->create('Price_form',array('url'=>array('controller'=>'Sale','action'=>'sale')));
echo $this->form->input('Price', array('type'=>'select','options'=>$price));
echo $this->form->end();

In SaleController:

$post_data = $this->request->data['Price_form']['Price'];

If so,I get only selected value.Now,I want to get all values such as: 100,200,300..
My Cakephp version is 2.5.7.
If know ways,help me plz...!

3
Why? ps, please always mention your exact CakePHP version! - ndm
cakephp version is 2.5.7 - hamony

3 Answers

0
votes

it is not possible like this.

You should passed to the view from Controller and you will have it.

In controller:

$price=array(100,200,300);
$this->set('price',$price);

And in your view

echo $this->form->input('Price', array('type'=>'select','options'=>$price));

this is the only way that i see

0
votes

Define your options in controller rather than view and then have them straight away from controller rather than from posted data

In controller

$prices = array(100, 200, 300);

    if ($this->request->is('post') || $this->request->is('put')) {
        $postedPrices = $this->request->data['Price_form']['Price']; // Selected Prices
        $allPrices = $prices; // All price options
    }

    $this->set(compact('prices')); // Set prices for view
0
votes

You might try to pass it in a hidden input field: (Did not test this)

View:

 $price = array('100','200','300');
 ...
 $allPricesAsString = implode(',',$price);
 $form->input('allPrices', array('value'=>$allPricesAsString,'type' => 'hidden')); 

Controller:

 $allPrices = explode(',',$this->request->data['Price_form']['allPrices']);

But I actually do not understand why you would set the data in the view. Usually you should do this in the controller like it was said before.