[eluser]Mithun[/eluser]
Hi All,
I have an issue with re-populating the field values on the add view once the user submits the form and the validation fails,
Problem is i can get values from set_value function in the view
Here is my controller
Code:
<?php
class Locations extends MY_Controller {
function Locations()
{
parent::MY_Controller();
}
function add()
{
if(empty($_POST))
{
//$data['customers'] = $this->db->get('customers');
$data = array();
$this->template->write_view('content','locations/add',$data);
}
else
{
$this->load->library('validation');
$rules['name'] = "trim|required|min_length[1]|max_length[12]|xss_clean";
$rules['assigned_id'] = "trim|required|";
$this->validation->set_rules($rules);
/*
$data = array(
'name' => $_POST['name'],
'address' => $_POST['address'],
'assigned_id' => $_POST['assigned_id'],
);
*/
if ($this->validation->run()){
$this->db->insert('locations',$data);
redirect('/locations/index/');
} else {
//print_r($data);
$this->template->write_view('content','locations/add',$data);
//$this->template->write_view('content','locations/add');
}
}
$this->template->render();
}
}
here is my view
Code:
<?php
$name = array(
'id'=>'location_add_name',
'name' => 'name',
'value' => set_value('name')
);
$address = array(
'id' => 'location_add_address',
'name' => 'address',
'value' => set_value('address')
);
$assigned_id = array(
'id' => 'location_add_address_assigned_id',
'name' => 'assigned_id',
'value' => set_value('assigned_id')
);
print_r($name);
?>
<div id='locations_add' class="add">
<?php echo form_open('locations/add');?>
<?php echo validation_errors(); ?>
<div class='field_wrapper'>
<div class='field_label'>
<?php echo form_label('Name', $name['id']);?>
</div>
<div class='field_input'>
<?php echo form_input($name);?>
</div>
</div>
<div class='field_wrapper'>
<div class='field_label'>
Address
</div>
<div class='field_input'>
<?php echo form_input($address);?>
</div>
</div>
<div class='field_wrapper'>
<div class='field_label'>
Assigned User
</div>
<div class='field_input'>
<?php echo form_input($assigned_id);?>
</div>
</div>
<div class='form_submit'>
<?php echo form_submit('submit','Add');?>
</div>
<?php echo form_close();?>
</div>
And I'm not getting anything from set_value('name') ;-(