Welcome Guest, Not a member yet? Register   Sign In
form_dropdown() always returns 0
#1

[eluser]EthanSP[/eluser]
Why is it that this form_dropdown() always returns 0?

form_dropdown($fby,$fy_values,$fy_default) // in view

where,

$fby is $data['fby'] = array('name'=>'birth_year'); // in model

$fy_values is $data['fy_values'] = $datelib->show_years(); // in model

function show_years() {
for ($x=date('Y')-150; $x<=date('Y'); $x++)
$years[] = $x;
return $years;
}

$fy_default is $data['fy_default'] = array_search(date('Y'),$data['fy_values']); // in model

In the controller:

if($this->input->post('mysubmit')) {
$this->mdl_demographics->save();
}

In the model:

$db_array = array('last_name' => $this->input->post('birth_year'));

Result in db:

last_name = 0

Why?
#2

[eluser]xwero[/eluser]
You are using an array for the dropdown name, the first argument only takes strings. I guess if you look at the source of your page you will see something like
Code:
<select name="Array">
#3

[eluser]EthanSP[/eluser]
[quote author="xwero" date="1212071956"]You are using an array for the dropdown name, the first argument only takes strings. I guess if you look at the source of your page you will see something like
Code:
<select name="Array">
[/quote]

I patterned my work with that of the CI User Guide's, which is:
form_dropdown('shirts', $options, 'large');

where,

I replaced:
'shirts' w/ a variable ($fby),
$options w/ another variable/array ($fby_values), and
'large' w/ yet another variable ($fby_default).

And looking at my source code, I didn't use <select name="Array">, instead:

function show_years() {
for ($x=date('Y')-150; $x<=date('Y'); $x++)
$years[] = $x;
return $years;
}
#4

[eluser]xwero[/eluser]
Quote:$fby is $data[’fby’] = array(’name’=>’birth_year’); // in model
the $fby variable is an array but it should be a string. Or you would have to do
Code:
form_dropdown($fby['name'])

If you look to the source of your rendered page in your browser i think you will see the snippet i posted in my previous response.
#5

[eluser]EthanSP[/eluser]
xwero,

I see. So, that's the way to do it. May I just make a follow-up question: How can I display its value instead of index only? Because $fby['name'], where 'name' = 'birth_year,' when used here: 'birthday' => $this->input->post('birth_year'), outputs the index only and not its value. How can I display the value?

Also, if I display the source of the rendered page, all I see are HTML frame tags and other elements.

BTW, thanks for your time & for imparting your knowledge.


Ethan
#6

[eluser]poji23[/eluser]
Hi,

Just a small fix in your show_years method and it's done:

Code:
function show_years() {
for ($x=date('Y')-150; $x<=date('Y'); $x++)
$years[$x] = $x;
return $years;
}
#7

[eluser]EthanSP[/eluser]
It worked like magic! Thank you very much.




Theme © iAndrew 2016 - Forum software by © MyBB