[eluser]yello[/eluser]
Hey there,
I want to use the validation class but I am having an error and I don't know what caused it.
Here is my controller:
Code:
<?php
class Register extends Controller {
function Register()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->library('validation');
$rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['password'] = "trim|required|matches[passconf]|md5";
$rules['passconf'] = "trim|required";
$rules['email'] = "trim|required|valid_email";
$rules['city'] = "trim|required";
$rules['state'] = "trim|required";
$rules['country'] = "trim|required";
$rules['details'] = "trim|required";
$this->validation->set_error_delimiters('<li style="color:red">', '</li>');
$this->validation->set_rules($rules);
if ($this->validation->run() == FALSE)
{
$query = $this->db->query('SELECT * FROM countries;');
$data['countries'] = $query->result();
$this->load->view('register/information', $data);
}
else
{
//do something with the vars
}
}
}
?>
Here is my view:
Code:
<?=$this->load->view('includes/header');?>
<?=$this->validation->error_string; ?>
<h1>Modchip 411 Registration Form</h1>
<?=form_open('register'); ?>
<h5>Username</h5>
<input type="text" name="username" value="<?=$this->validation->username;?>" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="<?=$this->validation->email;?>" size="50" />
<h5>City</h5>
<input type="text" name="city" value="<?=$this->validation->city;?>" size="20" />
<h5>State/Province (if any)</h5>
<input type="text" name="state" value="<?=$this->validation->state;?>" size="20" />
<h5>Country</h5>
<select type="text" name="country">
<?php foreach($countries as $country):?>
<option value="<?=$country->name;?>" <?= $this->validation->set_select('country', '<?=$country->name;?>'); ?> ><?=$country->name;?></option>
<?php endforeach;?>
</select>
<h5>Service you offer</h5>
<h6>Modchips:</h6>
Xbox <input type="checkbox" name="xbox" value="1" <?= $this->validation->set_checkbox('xbox', '1'); ?>/><br>
Xbox 360 <input type="checkbox" name="xbox 360" value="1" <?= $this->validation->set_checkbox('xbox 360', '1'); ?>/><br>
PS1 <input type="checkbox" name="ps1" value="1" <?= $this->validation->set_checkbox('ps1', '1'); ?>/><br>
PS2 <input type="checkbox" name="ps2" value="1" <?= $this->validation->set_checkbox('ps2', '1'); ?>/><br>
PS3 <input type="checkbox" name="ps3" value="1" <?= $this->validation->set_checkbox('ps3', '1'); ?>/><br>
Gamecube <input type="checkbox" name="gamecube" value="1" <?= $this->validation->set_checkbox('gamecube', '1'); ?>/><br>
Wii <input type="checkbox" name="wii" value="1" <?= $this->validation->set_checkbox('wii', '1'); ?>/><br>
PSP <input type="checkbox" name="psp" value="1" <?= $this->validation->set_checkbox('psp', '1'); ?>/><br>
<h6>Other</h6>
Repairs <input type="checkbox" name="repairs" value="1" <?= $this->validation->set_checkbox('repairs', '1');?>/><br>
Tuning <input type="checkbox" name="tuning" value="1" <?= $this->validation->set_checkbox('tuning', '1');?>/><br>
<h5>Details</h5>
<textarea name="details" rows="10" cols="70"><?=$this->validation->details;?></textarea>
<h5>Password</h5>
<input type="password" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="password" name="passconf" value="" size="50" />
<div><input type="submit" value="Submit" style="font-size:150%"/></div>
</form>
<?=$this->load->view('includes/footer');?>
I get bunch of notice like these:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: username
That error is repeated for each element in the form. Is this CI related bug? I can't find the damn problem!!
Thanks