Welcome Guest, Not a member yet? Register   Sign In
Form Re-populate Problem
#1

[eluser]Multisnet[/eluser]
I need some help please.. I'm trying to repopulate a form.

in controller:
Code:
function validateUserRegistration(){
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required');
if ($this->form_validation->run() == FALSE){
$this->template->write_view('reg_conteudos_centro', 'paciente_form_registo');
$this->template->render();
}
else{
echo("Success!!");
}
}

in view:
Code:
(...)
<?=form_open('registo_p_ctr/validateUserRegistration'); ?>
<?php echo validation_errors(); ?>
<label>
&lt;input name="name" type="text" id="name" style="width:280px;" value="&lt;?php echo set_value('name'); ?&gt;"&gt;
</label>
(...)
&lt;?=form_close(); ?&gt;

When the validation fails it shows again the form. The errors are displayed correctly, but the form doesn't show the values that user previously entered. However I could repopulate the form if i use $_POST['field_name'].

Could you help me? After reading for a while, I can't realize what I'm doing wrong..
#2

[eluser]Multisnet[/eluser]
PS: In my form I've more fields. Of course that the above code isn't a good example because to display the error (required) the User need to submit the form without filling the name field, so it's obviously that there wouldn't be nothing to repopulate.
#3

[eluser]Multisnet[/eluser]
I'm so dumb... I realize what I'm doing wrong.. As I'm only testing I forgot to apply validation rules to other fields so the form_validation couldn't "know" the fields.

Sorry Wink
#4

[eluser]TheFuzzy0ne[/eluser]
I don't know how the template parser you're using works, so what I'd suggest, is that you call set_value() from within your controller, and assign the return value as a variable to be used by your view.

EDIT: D'oh!




Theme © iAndrew 2016 - Forum software by © MyBB