[eluser]Gica78R[/eluser]
Hello, this is my first post here. I'm dealing with the same problem (repopulating form fields), but it doesn't work with some fields even if I set validation rules. Here is a chunk of my controller and view code.
Controller action "signup":
Code:
$this->form_validation->set_rules('username', 'User name',
'trim|required|min_length[3]|max_length[20]|alpha_dash|xss_clean');
$this->form_validation->set_rules('email', 'Email',
'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password',
'trim|required|min_length[6]|max_length[20]|md5');
$this->form_validation->set_rules('password2', 'Repeat password',
'trim|required|matches[password]');
$this->form_validation->set_rules('first_name', 'Name',
'trim|max_length[50]|alpha|htmlentities|xss_clean');
$this->form_validation->set_rules('last_name', 'Surname',
'trim|max_length[50]|alpha|htmlentities|xss_clean');
I've set up validation rules for all the form fields.
View: signup_view
Code:
<?php echo form_open('user/signup'); ?>
<div class="form_required_field_label">User name</div>
<?php echo form_error('username'); ?>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="30" />
<div class="form_required_field_label">Email</div>
<?php echo form_error('email'); ?>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="60" />
<div class="form_required_field_label">Password</div>
<?php echo form_error('password'); ?>
<input type="password" name="password" size="30" />
<div class="form_required_field_label">Repeat password</div>
<?php echo form_error('password2'); ?>
<input type="password" name="password2" size="30" />
<div class="form_required_field_label">Name</div>
<?php echo form_error('first_name'); ?>
<input type="text" name="first_name" value="<?php set_value('first_name'); ?>" size="60" />
<div class="form_optional_field_label">Surname</div>
<?php echo form_error('last_name'); ?>
<input type="text" name="last_name" value="<?php set_value('last_name'); ?>" size="60" />
<div><input type="submit" value="Send" /></div>
</form>
I want fields username, email, first_name and last_name to be repopulated, but if I insert non valid data, only the username and email fields are repopulated; first_name and last_name do not. Did I make some obscene error?
Thank you very much,
Gica