Welcome Guest, Not a member yet? Register   Sign In
Prefilling my select menu and Radio button
#8

[eluser]sstalder[/eluser]
I think I have narrowed it down, take a look at this example:

Code:
class Test extends CI_Controller
{
    function index()
    {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('myselect', 'myselect', 'required');
        
        if ($this->form_validation->run() == FALSE)
        {
            $data['myselect'] = '';
        }
        else
        {
            $data = $_POST;
        }
        
        $this->load->view('form', $data);
    }
}

Code:
<form action="<?php echo current_url();?>" method="post">

    <select name="myselect">
        <option value=""></option>
        <option value="one"&lt;?php echo set_select('myselect', 'one'); ?&gt;>One</option>
        <option value="two"&lt;?php echo set_select('myselect', 'two'); ?&gt;>Two</option>
        <option value="three"&lt;?php echo set_select('myselect', 'three'); ?&gt;>Three</option>
    </select>
    <br />
    &lt;input type="submit" name="sub" value="send" /&gt;

&lt;/form&gt;

It seems like with the form_validation library loaded the values don't persist across a postback however if you set the data manually as I did above you get the expected behavior.


Messages In This Thread
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 05:39 AM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 06:49 AM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 10:35 AM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 10:59 AM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 11:34 AM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 11:44 AM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 12:06 PM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 01:11 PM
Prefilling my select menu and Radio button - by El Forum - 02-25-2011, 01:40 PM



Theme © iAndrew 2016 - Forum software by © MyBB