CodeIgniter Forums
Help - Validate & Repopulate a Dropdown? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help - Validate & Repopulate a Dropdown? (/showthread.php?tid=10649)



Help - Validate & Repopulate a Dropdown? - El Forum - 08-07-2008

[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


Help - Validate & Repopulate a Dropdown? - El Forum - 08-07-2008

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


Help - Validate & Repopulate a Dropdown? - El Forum - 08-18-2008

[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);



Help - Validate & Repopulate a Dropdown? - El Forum - 08-18-2008

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


Help - Validate & Repopulate a Dropdown? - El Forum - 08-18-2008

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