Welcome Guest, Not a member yet? Register   Sign In
Passing selected value to form_dropdown
#1
Question 

Hello,

I'm trying to pass a selected value from one controller to another and have that value be the default for the dropdown.

I have a view with a form that includes a dropdown. The options in the dropdown are passed as arguments from the controller after the model gets the data from the database. Using the set_value option, when the form submission fails validation, the selected value shows up, so everything works as expected.

In my main landing page, I have a dropdown with several buttons in a form. The user chooses a dropdown option then a button. The button is processed by the controller and directs to another controller, where I want to pass along the value of the original select option to be used as the default value for the select on the second controller. 

I was thinking of passing the value as sessiondata, then doing a check if it exists - if it does, use set_select(), if it doesn't, then use set_value. Would that be the best way to do it?

Thanks
Reply
#2

You could use flash data.

http://www.codeigniter.com/user_guide/li...#flashdata

Or just pass it as a normal variable such as redirect('mycontroller/mymethod/myvariable')

I hope that helps,

Paul.
Reply
#3

(11-03-2015, 05:42 PM)PaulD Wrote: You could use flash data.

http://www.codeigniter.com/user_guide/li...#flashdata

Or just pass it as a normal variable such as redirect('mycontroller/mymethod/myvariable')

I hope that helps,

Paul.

Thank you PaulD - appreciate the response.

I was being too sneaky for my own good. I was checking for the flashdata entry and setting a variable to the value, otherwise use "set_value('fieldname')", then passing the variable to the form_dropdown call. What I ended up doing was just put the echo form_dropdown(blah blah blah) into the if statement and it worked. 

I'd thought about the method variable option, but have the form built in the index function. Probably not best practice, but . . . 

Thanks!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB