set_select() issue |
[eluser]ebohling[/eluser]
i'm sure i'm pulling a newbie mistake, but even after scouring the forums, wikis, user guide and google i cannot find my issue (probably bonehead move #2)... i'm simply trying to select the user's drop down selection after a validation error occurs. my HTML (view) code is simple enough (i'm showing two methods, please feel free to explain which one is better an why...remember i'm a newbie): <label for="opportunity-name-select">Opportunity:</label><br/> <?=form_dropdown('opportunity-name-select', $ops, '', 'id="opportunity-name-select"');?> <?=form_error('opportunity-name-select'); ?> <label for="scenario-name-select">Scenario:</label><br/> <select name="scenario-name-select" id="scenario-name-select"> <optgroup label="scenarios"> <option value="0">-- I want to add my own Scenario. --</option> <?php foreach($scen as $row):?> <option value="<?=$row->scenario_id; ?>" <?=set_select('scenario-name-select', $row->scenario_id); ?>><?=$row->scenario_name; ?></option> <?php endforeach;?> </optgroup> </select> the database (model) code (again two methodologies used, best practices feedback welcome): function getOpportunities() { $query = $this->db->query('select opportunity_name, opportunity_id from Opportunities order by opportunity_name'); if ($query->num_rows() < 0) { show_error('Database is empty!'); } else { $q = $query->result_array(); foreach($q as $cRow) { $data['opportunities'][$cRow['opportunity_id']] = ($cRow['opportunity_name']); } return $data; } } function getScenarios() { $query = $this->db->query('select scenario_name, scenario_id from Scenarios order by scenario_name'); if ($query->num_rows() < 0) { show_error('Database is empty!'); } else { // $q = $query->result_array(); // foreach($q as $cRow) { // $data['scenarios'][$cRow['scenario_id']] = ($cRow['scenario_name']); // } // return $data; return $query->result(); } } what am i doing wrong? upon a validation error, the drop down list just defaults back to first option. let me know if you need to see more code to answer. thanks, --bb--
[eluser]richwalkup[/eluser]
I'm quite sure this is a bug - I have worked around it myself over the past couple days and considered entering a bug report on it as well. You can find a workaround here (but it requires modifying the core): http://ellislab.com/forums/viewreply/593430/ #EDIT: I have found this to have other buggy artifacts - don't use it. I don't have time to figure out what it is right now but there is an issue here that should be easily worked around without adding blank rules for every field.
[eluser]seanloving[/eluser]
I just posted a question as a reply to another thread, but I'm not sure if it will get the attention of the larger audience. I'm not trying to post twice, but here's my question... http://ellislab.com/forums/viewthread/11...80/#594552 it appears I might be facing similar issue. Anyone? --Sean Loving
[eluser]richwalkup[/eluser]
I'm going to reply in this forum because I think the issue is very likely related to this bug. The fast way to find out is to add an empty validation requirement to your code. If something like the code below does not fix your issue, then it's more likely related to the usage and/or scope of the variable at the time you are attempting to access it and then I would have to see more of the code to understand the full scope of its usage. Code: $this->form_validation->set_rules('group_id', 'Group', '');
[eluser]seanloving[/eluser]
I tried your suggestion on line 6 but my line 36 still seems to cause same error. Note: this function comes with Auth Library by Adam Griffith. I want a simple modification to display the three possible values of the group_id field (users table) in a pull-down select list: admin sales customer The default value to display on the item list should be the value of $userdata->group_id. Code: function register($login = TRUE, $edit = FALSE, $id = NULL) Code: <div id="login"> |
Welcome Guest, Not a member yet? Register Sign In |