Question about repopulating fields in my form - El Forum - 10-25-2007
[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.
Question about repopulating fields in my form - El Forum - 10-26-2007
[eluser]dedenf[/eluser]
i always do this to process the form
Code: if ($this->validation->run() == false){
$this->load->view('register',$data);
}else {
//your filter and other process
}
and i use the input class to sanitize the submitted data from the form.
Code: $this->input->post('college');
$this->input->post('notified');
Question about repopulating fields in my form - El Forum - 10-26-2007
[eluser]caole261188[/eluser]
Thank you, I never knew about this input library.
However what I'm asking is, how to fill in the form again with the information the user supplied before. For example, he fills out the form with some mistakes, and then when he submits he gets an error message with the form reloaded. But in my case, the fields are not refilled with information user presented before. Sorry for my English, I don't know how to state it more clearly
Question about repopulating fields in my form - El Forum - 05-04-2009
[eluser]Ray Luevano[/eluser]
thanks guys your info worked just fine to me.
I changedCode: 'value' => $this->validation->field);
for Code: 'value' => $this->input->post('field')
in my own code to repopulating a form after an error.
I'm a Beginner into this so please share knowledge :lol:
excuse my english jeje
|