[eluser]caole261188[/eluser]
I have a registration form, in which there's a drop down list.
I included the validation library in the form controller, and then set rules for it. After that I tried to repopulate the values which the user tried to enter before getting to error. Every thing works fine for input textbox, but for dropdown list (select) or radio and checkbox, I really don't know how to do it. Can you please show me?
Here's my form view:
Code:
<?php echo $this->validation->error_string;?>
<?php echo form_open('register'); ?>
<p><label for='username'>Username: *</label><br /><?php echo form_input($username); ?></p>
<p><label for='password'>Password: *</label><br /><?php echo form_password($password);?></p>
<p><label for='passwordconf'>Repeat Password: *</label><br /><?php echo form_password($passwordconf);?></p>
<p><label for='email'>Email: *</label><br /><?php echo form_input($email);?></p>
<p><label for='college'>College:</label><br /><?php echo form_dropdown('college',$college);?></p>
<p><label for='fullname'>Fullname: *</label><br /><?php echo form_input($fullname);?></p>
<p><label for='phone'>Phone:</label><br /><?php echo form_input($phone);?></p>
<p><label for='phonemail'>Phone email address:</label><br /><?php echo form_input($phonemail);?></p>
<p><label for='notified'>Would you like to be notified by email when someone bids for your items?</label><br /><?php echo form_radio($notifiedyes);?> Yes<br /><?php echo form_radio($notifiedno);?> No</p>
<p><label for='country'>Country: *</label><br /><?php echo form_dropdown('country',$country);?></p>
<?php echo form_submit('submit','Register!');?>
And here's the portion in the controller file, to validate and repopulate the form fields:
Code:
$this->load->helper('form');
$rules['username'] = 'trim|required|min_length[5]|alpha_dash|xss_clean';
$rules['password'] = 'required|matches[passwordconf]|alpha_numeric|md5';
$rules['passwordconf'] = 'required';
$rules['email'] = 'trim|required|valid_email';
$rules['fullname'] = 'trim|required';
$rules['country'] = 'required';
$this->validation->set_rules($rules);
$fields['username'] = 'Username';
$fields['password'] = 'Password';
$fields['passwordconf'] = 'Repeat Password';
$fields['email'] = 'Email Address';
$fields['fullname'] = 'Full name';
$fields['country'] = 'Country';
$this->validation->set_fields($fields);
$this->validation->set_error_delimiters('<h3>','</h3>');
$data['username'] = array(
'name' => 'username',
'id' => 'username',
'maxlength' => '40',
'size' => '40',
'value' => $this->validation->username);
$data['password'] = array(
'name' => 'password',
'id' => 'password',
'maxlength' => '30',
'size' => '30',
'value' => $this->validation->password);
$data['passwordconf'] = array(
'name' => 'passwordconf',
'id' => 'password',
'maxlength' => '30',
'size' => '40');
$data['email'] = array(
'name' => 'email',
'id' => 'email',
'maxlength' => '40',
'size' => '40',
'value' =>$this->validation->email);
$data['college'] = array(
'apm' => 'APM - Asia Pacific Management',
'aps' => 'APS - Asia Pacific Studies',
'mba' => 'MBA (Graduate School)',
'ips' => 'IPS/APS (Graduate School)',
'phd' => 'PhD (Graduate School)');
$data['fullname'] = array(
'name' => 'fullname',
'id' => 'fullname',
'maxlength' => '40',
'size' => '40');
$data['phone'] = array(
'name' => 'phone',
'id' => 'phone',
'maxlength' => '12',
'size' => '12');
$data['phonemail'] = array(
'name' => 'phonemail',
'id' => 'phonemail',
'maxlength' => '30',
'size' => '30');
$data['notifiedyes'] = array(
'name' => 'notified',
'id' => 'notified',
'value' => 'yes',
'checked' => TRUE);
$data['notifiedno'] = array(
'name' => 'notified',
'id' => 'notified',
'value' => 'no',
'checked' => FALSE);
blah blah etc.
It may look long, and I'm just a beginner. So I really need to learn more from you.
Thanks in advance.