[eluser]Gukkie[/eluser]
Hi all, i created my own helper which gets the country list from the database, the thing is everything works fine except that when i post the form and if errors are encountered, the country field does not hold its value, this is my helper code:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
if(!function_exists('country_dropdown'))
{
function country_dropdown($name='', $selection=NULL, $attributes=array())
{
$CI =& get_instance();
$CI->load->database();
// Get values from database
$sql = "SELECT CountryId, Country FROM countries";
$query = $CI->db->query($sql);
if(!empty($attributes))
{
$output = "<select name='{$name}' {$attributes}>";
}
else
{
$output = "<select name='{$name}'>";
}
$selected = NULL;
foreach($query->result_array() as $row)
{
$value = $row['CountryId'];
$country = $row['Country'];
$country_array = array($value => $country);
foreach($country_array as $key => $value)
{
if($key === $selection)
{
$selected = "SELECTED";
}
$output .= "<option value='{$key}' {$selected}>{$value}</option>";
$selected = NULL;
}
}
$output .= "</select>";
return $output;
}
}
?>
HTML:
country_dropdown('country', $this->input->post('country'), '');
Any ideas?