[eluser]Unknown[/eluser]
I am trying to re-populate the fields of a form that has not been filled out properly with the information that was entered. In other words, the user will not need to completely fill out the form again as the previously entered values in each field will be kept on the form. Here is part of my code in the controller:
Code:
$this->load->library('validation');
$rules['username'] = "required";
$rules['password'] = "required";
$rules['email'] = "required";
$rules['zipcode'] = "required";
$this->validation->set_rules($rules);
$fields['username'] = 'User Name';
$fields['password'] = 'Password';
$field['email'] = 'Email';
$field['zipcode'] = 'Zip Code';
$this->validation->set_fields($fields);
This next code is in the views:
<div>
<label for="name">Username</label>
<input id="username" name="username" type="text" value="<?php echo $this->validation->username;?>">
<b class="validation2">validation text</b>
</div><br>
<div>
<label for="password">Password</label>
<input id="password" name="password" type="password" value="<?php echo $this->validation->password;?>">
<b class="validation2">validation text</b>
</div><br>
<div>
<label for="email">email</label>
<input id="email" name="email" type="text" value="<?php echo $this->validation->email;?>">
<b class="validation2">validation text</b>
</div><br>
<div>
<label for="zipcode">Zip Code</label>
<input id="zipcode" name="zipcode" type="text" value="<?php echo $this->validation->zipcode;?>">
<b class="validation2">validation text</b>
It only properly displays for user name and password.
I get this error type for email and zipcode:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Validation::$email
Filename: user/register.tpl
I'm not sure what I am doing wrong.
edit: here is the controller for it
Code:
function register($status = NULL)
{
$this->load->library('validation');
$fields['username'] = "User Name";
$fields['password'] = 'Password';
$field['email'] = 'Email';
$field['zipcode'] = 'Zip Code';
$this->validation->set_fields($fields);
$rules['username'] = "required|alpha_numeric|min_length[3]|max_length[20]";
$rules['password'] = "required|matches[confirm_password]|min_length[4]|max_length[20]";
$rules['confirm_password'] = "required";
$rules['email'] = "required|valid_email";
$rules['confirm_email'] = "required|valid_email|matches[email]";
$rules['zipcode'] = "required";
$this->validation->set_rules($rules);
if($status == 'process')
{
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password'),
'email' => $this->input->post('email'),
'zipcode' => $this->input->post('zipcode'),
'type' => '1'
);
log_message('debug', 'data array ok');
if ($this->validation->run() == FALSE)
{
$this->load->view('user/register.tpl');
}
else
{
$this->user_library->register($data);
}
}
elseif($status == 'complete')
{
$stage = $this->load->view('user/register_complete.tpl','' , TRUE);
$data = array('stage' => "$stage", 'page_title' => 'Account Registration');
$this->parser->parse('template/main.tpl', $data);
}
else
{
$this->load->library('validation');
$rules['username'] = "required";
$rules['password'] = "required";
$rules['email'] = "required";
$rules['zipcode'] = "required";
$this->validation->set_rules($rules);
$fields['username'] = 'User Name';
$fields['password'] = 'Password';
$field['email'] = 'Email';
$field['zipcode'] = 'Zip Code';
$this->validation->set_fields($fields);
$stage = $this->load->view('user/register.tpl','' , TRUE);
$data = array('stage' => "$stage", 'page_title' => 'Register User Account');
$this->parser->parse('template/main.tpl', $data);
}
}