Welcome Guest, Not a member yet? Register   Sign In
form_dropdown and set_select
#1

[eluser]bhbutter123[/eluser]
I am not getting the result I want out of set_select when using form_dropdown. I know how to use both but the set_select is not working. The second setting in the set_select function is for the value of the option but if you are supplying the form_dropdown an array to build a list of options I cannot think of how to set the second setting of the set_select function. Would someone please show me working code so that I can see how it is done.
#2

[eluser]bigtony[/eluser]
The set_select() function is intended for use when you code the select manually. If you're using the form_dropdown() then the third parameter is simply the value to use as the default, so no need to use set_select - just pass the value.
#3

[eluser]Tandubhai[/eluser]
Simply set your value to thrid parameter using form_dropdown() will fulfil your need.
But with check-box and radio-button Codigniter has no any such parameter to set as checked. You can simply create your own helper file to overcome this.
Tandubhai
#4

[eluser]ericrjones1[/eluser]
For the form_dropdown function you don't need to use the set_select function.

For the form_dropdown function use the following code as guidance.

Code:
echo form_dropdown('post_status', $status, set_value('post_status', 'published'), $js);
For this code, $status is an array passed from the controller. The third parameter should be the set_value function. The first parameter in the set_value function will pull the value of the dropdown from $this->input->post('post_status'), and the second is the default value.

For the form_multiselect function use the following code as guidance.

Code:
echo form_multiselect('post_tags[]', $tags, set_value('post_tags[]'), $input);
Same explanation as above, but with form_multiselect.
#5

[eluser]Peter Lachky[/eluser]
Hi slingshoteric,

are you sure your proposal works? Because for me it does not but there is still a chance that I am doing something wrong.

Code:
<?php echo form_dropdown('kategoria', $kategorie, set_value('kategoria', $kategoria)) ?>

does not re-populate. It looks like the only way how to achieve this is:
Code:
<?php echo form_dropdown('kategoria', $kategorie, $this->input->post('kategoria') ? $this->input->post('kategoria') : $kategoria) ?>

Am I right or just missing anything?
#6

[eluser]ericrjones1[/eluser]
Peter,

I am pretty sure that my proposal works.

[quote author="Peter Lachky" date="1261542309"]

Code:
<?php echo form_dropdown('kategoria', $kategorie, set_value('kategoria', $kategoria)) ?>

[/quote]

Your proposed solution for resetting the form...

[quote author="Peter Lachky" date="1261542309"]

Code:
<?php echo form_dropdown('kategoria', $kategorie, $this->input->post('kategoria') ? $this->input->post('kategoria') : $kategoria) ?>

[/quote]

...is similar to what the set_value function is doing (check it out in the CI_Form_Validation Class).

Code:
function set_value($field = '', $default = '')
{
    if ( ! isset($this->_field_data[$field]))
    {
        return $default;
    }
        
    return $this->_field_data[$field]['postdata'];
}

I would check for the following items:

1. $kategoria is a key in the array $kategorie
2. $kategoria is of the expected type and value
3. check the return value of set_value() and how that is different from the $this->input->post() value




Theme © iAndrew 2016 - Forum software by © MyBB