Select widget in post problem

Permalink 1 user found helpful
hi mates i have this code in edit.php

<form id="test" method="post" action="<?php echo $this->action('myfunc')?>">
   <?php echo $form->select('csname', $this->controller->getmyfunc())?>
   <?php echo $form->submit('submit', 'apply'); ?>
</form>


but when i receive the the variable with post in my controller.php
$myVAR = $this->post('csname');

i only get the index key [0,1,2,3,4,5,6] of the selected item but i can't figure out how to tell the select widget to pass the value instead of key

thx for any help [i bet is somenthing stupid but well it happens]

 
ScottC replied on at Permalink Best Answer Reply
ScottC
make your function return a value indexed key

foreach($whateverTheArrayIs as $value){
$arr[$value]= $value;
}

return $arr;

But generally you want to store the index which relates to another record by its id or something.
jrch2k10 replied on at Permalink Reply
thanks scott, it logic do it this way i just imagined there was a concrete5 way like setting it with api but this will do

many thanks
jrch2k10 replied on at Permalink Reply
mmm i just realizaed that select is not delivering an array on post but a single regular variable with an integer value

is_array return always false

maybe another trick you can think of??
jbx replied on at Permalink Reply
jbx
I think you misunderstood what Scott said.

The result of $this->controller->getmyfunc() must be an associative array. That way, $this->post('csname') will return the string not an integer.

so getmyfunc() should look like this:
function getmyfunc() {
  return array('value1' => 'value1', 'value2' => 'value2');
}

not:
function getmyfunc() {
  return array('value1', 'value2');
}


Does that make sense?

Jon
jrch2k10 replied on at Permalink Reply
well the original array to select is from $db->getcol($sql) array is not handcoded but i think it work like this

array('0' => "register1", '1' => "register2") so in the post im getting $key and not the $value

but let me find the source of getcol to be sure
jrch2k10 replied on at Permalink Reply
effectively var_dump() shows
array(4) { [0]=> string(23) "register1" [1]=> string(10) "register2" [2]=> string(8) "register3" [3]=> string(10) "register4" }

so is an associative array
jrch2k10 replied on at Permalink Reply
well i solved it very hackishly but works

$value = $array[$index];return $value;


array is the original array submitted to the select and index is the received index from the post