Welcome Guest, Not a member yet? Register   Sign In
Help - Validate & Repopulate a Dropdown?
#1

[eluser]hawthornpublications[/eluser]
I've used the form_dropdown function to generate a dropdown menu using an array of options. After the form fails validation, I want the dropdown to maintain the selection but can't figure out how to do it.
Code:
$meals = array(
'select_one' => 'Select One',
'breakfast' => 'Breakfast',
'lunch' => 'Lunch',
'dinner' => 'Dinner'
);

...

<?= form_dropdown('meals', $meals, 'select_one') ?>

In the form_dropdown function I have the default currently set to
Code:
'select_one'
but I imagine that's where I might put
Code:
$this->validation->meals
or something similar.. but it doesn't work.

Any ideas? Smile
#2

[eluser]hawthornpublications[/eluser]
Wait. I tried it again and it worked. Nevermind - thanks all!
#3

[eluser]hawthornpublications[/eluser]
Here is a more detailed explanation.

View File

Code:
// Set menu options

$fruit_options = array(
'bananas' = 'Fresh Bananas',
'apples' = 'Delicious Apples',
'oranges' = 'Juicy Oranges'
);

// Create the form drop down

<?= form_dropdown('fruit', $fruit_options, $this->validation->fruit); ?>

Controller
Code:
$fields['fruit'] = "Fruit Options";
$this->validation->set_fields($fields);
#4

[eluser]The Wizard[/eluser]
Hello Smile
code
#5

[eluser]The Wizard[/eluser]
Code:
.. $this->validation->code );




Theme © iAndrew 2016 - Forum software by © MyBB