[eluser]eger[/eluser]
Sure, here is my method in the controller
Code:
function request($trackId = '')
{
$playlist = $this->playlist->get();
$playlisResult = $playlist->result();
foreach ($playlisResult as $track) {
$optionsTrack[$track->ID] = "$track->artist - $track->title";
}
$this->form_validation->set_rules('ID', 'Track ID', 'trim|required|integer');
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('error', 'Cause Error', 'trim|required');
$view['form_open'] = form_open('playlist/request');
$view['input_track'] = form_dropdown('ID', $optionsTrack);
$view['input_name'] = form_input('name', set_value('name', 'Your Name'));
if ($this->form_validation->run() == FALSE)
{
$this->load->view('reqform', $view);
}
else
{
$this->load->view('reqform_success');
}
}
Here is the reqform.php view
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?= $form_open ?>
<h5>Track</h5>
<?= $input_track ?>
<h5>Name</h5>
<?= $input_name ?>
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>
In this example, the error field always fails (cause it does not exist). It keeps the correct selected track field from the dropdown on error and displays 'Your Name' in the name field on first load.
- The name field is populated with 'Your Name' on load (expected)
- The name field is not repopulated on error (not expected)
- The track dropdown IS repopulated on error (not expected)
Hope this makes some sense. Not sure why this happens.