Welcome Guest, Not a member yet? Register   Sign In
about form validation, data didn't repopulated
#1

[eluser]qwang[/eluser]
i found that data without validate rules wont repopulate
is that right?

if so how can to prevent this, add rules for every field?

that's what confused me
#2

[eluser]mddd[/eluser]
That is correct. The form validation library only loads variables that are mentioned in the rules definition.
So you'll have to add a rule (even a simple one, like 'trim' to remove whitespace) to each field.
#3

[eluser]InsiteFX[/eluser]
look up set_value in the users_guide

InsiteFX
#4

[eluser]qwang[/eluser]
[quote author="mddd" date="1282150556"]That is correct. The form validation library only loads variables that are mentioned in the rules definition.
So you'll have to add a rule (even a simple one, like 'trim' to remove whitespace) to each field.[/quote]

thank you very much
it confused me for long time
after dive into the source code
i found why
#5

[eluser]qwang[/eluser]
another question
how to validate the field array
just like as
<input type="text" name="field" /
<input type="text" name="field" /
<input type="text" name="field" /
#6

[eluser]Jondolar[/eluser]
I don't think that works as an array. Only one field will be returned. If you want an array, you need to name the fields "field[]". Now, if you need to validate the array, you'll just need to write your own validation callback function on "field" which will pass in the array.

Good luck with your project.
#7

[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>
&lt;?php echo form_error('username'); ?&gt;
&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="30" /&gt;

<div class="form_required_field_label">Email</div>
&lt;?php echo form_error('email'); ?&gt;
&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="60" /&gt;

<div class="form_required_field_label">Password</div>
&lt;?php echo form_error('password'); ?&gt;
&lt;input type="password" name="password" size="30" /&gt;

<div class="form_required_field_label">Repeat password</div>
&lt;?php echo form_error('password2'); ?&gt;
&lt;input type="password" name="password2" size="30" /&gt;

<div class="form_required_field_label">Name</div>
&lt;?php echo form_error('first_name'); ?&gt;
&lt;input type="text" name="first_name" value="&lt;?php set_value('first_name'); ?&gt;" size="60" /&gt;

<div class="form_optional_field_label">Surname</div>
&lt;?php echo form_error('last_name'); ?&gt;
&lt;input type="text" name="last_name" value="&lt;?php set_value('last_name'); ?&gt;" size="60" /&gt;

<div>&lt;input type="submit" value="Send" /&gt;&lt;/div>
&lt;/form&gt;

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
#8

[eluser]cartalot[/eluser]
here it is, compare these two lines

Code:
value="&lt;?php echo set_value('username'); ?&gt;

Code:
value="&lt;?php set_value('first_name'); ?&gt;"

second one is missing the word 'echo', if you add that it should work
#9

[eluser]Gica78R[/eluser]
Thank you! I apologize, perhaps I was sleeping when I wrote and reread those few lines.

Thank you again,
Gica




Theme © iAndrew 2016 - Forum software by © MyBB