On my view I have a form_dropdown with some options
PHP Code:
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="input_country">Country</label>
<?php
$options[] = array();
foreach ($countries as $key => $value) {
$options['0'] = '--- Select Country ---';
$options[$value['iso_code_2']] = $value['name'];
}
echo form_dropdown('country_id', $options, '', array('class' => 'form-control', 'id' => 'input_country'));
?>
</div>
</div>
</div>
The iso code for Australia is AU
Question: If there is a error on form and have selected country how can I make sure it stays on the country so do not have to go through list again
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Register extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('localisation/country_model');
}
public function index()
{
if (($this->input->server("REQUEST_METHOD") == 'POST') && $this->validate())
{
// Success form area
}
if ($this->input->post('username'))
{
$data['username'] = $this->input->post('username');
} else {
$data['username'] = '';
}
if ($this->input->post('firstname'))
{
$data['firstname'] = $this->input->post('firstname');
} else {
$data['firstname'] = '';
}
if ($this->input->post('lastname'))
{
$data['lastname'] = $this->input->post('lastname');
} else {
$data['lastname'] = '';
}
if ($this->input->post('email'))
{
$data['email'] = $this->input->post('email');
} else {
$data['email'] = '';
}
if ($this->input->post('password'))
{
$data['password'] = $this->input->post('password');
} else {
$data['password'] = '';
}
$data['countries'] = $this->country_model->get_countries();
if ($this->input->post('country_id'))
{
$data['country_id'] = $this->input->post('country_id');
} else {
$data['country_id'] = '';
}
$this->load->view('default/template/common/header', $data);
$this->load->view('default/template/account/register', $data);
$this->load->view('default/template/common/footer', $data);
}
public function validate()
{
// Set the form validation rules
}
}
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!