Select widget in post problem
Permalink 1 user found helpful
hi mates i have this code in edit.php
but when i receive the the variable with post in my controller.php
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]
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]
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
many thanks
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??
is_array return always false
maybe another trick you can think of??
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:
not:
Does that make sense?
Jon
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
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
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
effectively var_dump() shows
so is an associative array
array(4) { [0]=> string(23) "register1" [1]=> string(10) "register2" [2]=> string(8) "register3" [3]=> string(10) "register4" }
so is an associative array
well i solved it very hackishly but works
array is the original array submitted to the select and index is the received index from the post
$value = $array[$index];return $value;
array is the original array submitted to the select and index is the received index from the post
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.