[eluser]pettechservices[/eluser]
I have form validation set up. It displays the proper error message at the top so I know validation is occuring, and working. However, the fields are not being repopulated. I've spent several days now trying to figure it out, reading the user guide, tutorials, etc. but I'm just stuck. For my views, they work as an include in a template. Not sure if this has anything to do with it, but I'm guessing not since the error messages still display.
Basically, they click an add New link, which calls client/client_entry. They submit the form, which goes to client/client_save, and validation runs there. If valid, saves the record and all is well (and this works). If invalid, it calls client_entry internally again and form displays (with proper error messages, but no repopulation).
Here is the code:
View (truncated):
<?php echo validation_errors(); ?>
<?php echo form_open('client/client_save');?>
<div style="float: left;padding-right: 5px; padding-bottom: 5px;">
<fieldset>
<legend>Client Information - Demographics</legend>
<ol>
<li>
<label for="clienttypeid">Client Type:</label>
<div id="clienttype">
<select tabindex="1" name="clienttypeid" id="clienttypeid">
<option value="0">Select Client Type...</option>
<?php foreach ($clienttypes->result() as $ct): ?>
<option value='<?=$ct->cfg_clienttypes_id?>'><?=$ct->cfg_clienttypes_desc?></option>
<?php endforeach; ?>
</select>
</div>
</li>
<li>
<label for="lastname" accesskey="f">Last name: </label>
<input type="text" class="textboxlong" id="lastname" name="lastname" tabindex="2" value="<?php echo set_value('lastname'); ?>" />
<?php /*
<br />
<span class="hint">Last name only</span>
*/ ?>
</li>
<li>
<label for="firstname" accesskey="l">First name: </label>
<input type="text" class="textboxlong" id="firstname" name="firstname" tabindex="3" value="<?php echo set_value('firstname');?>" />
</li>
<li>
<label for="address1">Address: </label>
<input type="text" class="textboxlong" id="address1" name="address1" tabindex="4" value="<?php echo set_value('address1');?>" />
</li>
</fieldset>
</div>
</form>
Controller:
<?php
class Client extends Controller {
function Client()
{
parent::Controller();
$this->load->database();
$this->load->library('form_validation');
$this->load->helper('form');
if (!$this->ion_auth->logged_in())
{
//$this->session->set_flashdata('message', '');
redirect('auth/login');
}
$this->load->model('mclient');
$this->load->model('mdropdowns');
$this->load->model('memployees');
$this->load->model('mlocations');
}
function index(){
redirect('/client/client_listall');
}
function client_entry() {
$this->load->library('ion_auth');
$this->_set_rules();
$data['title'] = "Client Entry Form";
$data['headline'] = "";
$data['message'] = "";
$data['include'] = $this->config->item("companyview").'client_entry';
$data['clienttypes'] = $this->mclient->get_clienttypes(FALSE);
$data['referralsources'] = $this->mdropdowns->get_referralsources();
$data['employees'] = $this->memployees->get_employeenames();
$data['locations'] = $this->mlocations->get_locations();
$this->load->vars($data);
$this->load->view('template');
}
function client_save() {
$this->load->helper('url');
$this->load->model('mclient','',True);
$this->_set_rules();
if ($this->form_validation->run() == FALSE){
$this->client_entry();
} else {
$this->mclient->SaveEntry();
// set form input name="id"
//$this->validation->id = $id;
// set user message
$data['message'] = '<div class="success">add new person success</div>';
// load view
redirect('client','refresh');
}
}
function _set_rules(){
$this->form_validation->set_rules('clienttypeid', 'Client ID', 'trim');
$this->form_validation->set_rules('firstname', 'First Name',
'trim|min_length[3]|max_length[30]');
$this->form_validation->set_rules('lastname', 'Last Name',
'trim|required|min_length[
$this->form_validation->set_rules('address1', 'Address Line 1', 'trim');
}
Thank you!