Welcome Guest, Not a member yet? Register   Sign In
form_validation - questions about set_value and set_rules
#1

[eluser]überfuzz[/eluser]
I have a question about the form_validation class.

In the following example theres two fields. One with some rules attached to it and one field with no rules.
Code:
$this->form_validation->set_rules('name', 'Name', 'required|min_length[2]|max_length[40]');
$this->form_validation->set_rules('example'); //tried to delete

And in the form I'm setting values like this:
Code:
<?php echo form_input('name', set_value('name')); ?>
<?php echo form_input('example', set_value('example')); ?> // if set_rules->example deleted value="[empty]"

However, I deleted the line with example because there where no rules, no need setting it then was the idea. But if I delete it the value isn't stored , value="[empty]", if the user fires the form submit. Is there an other way of passing the input in a field with no rules inserted by the user? Or should I always have rules to every field like; min_lenght, max_length etc?
#2

[eluser]HobbesTheTiger[/eluser]
I'm wondering the same thing.
And I found a report in the bug tracker:
http://codeigniter.com/bug_tracker/bug/7910/

[quote author="überfuzz" date="1253542178"]
Is there an other way of passing the input in a field with no rules inserted by the user?
[/quote]
#3

[eluser]rogierb[/eluser]
If you want to use set_value(), then you need to let the form validation class know a fields exists. When Ik don't need a rule, I use either "trim" or a custom rule the just spits out "true".
#4

[eluser]Unknown[/eluser]
I use...

Code:
if ($_POST)
{
   foreach ($_POST as $key => $field)
   {
      $this->form_validation->set_rules( $key, 'No Error', 'trim');
   }
}

Hope that helps.

Greg




Theme © iAndrew 2016 - Forum software by © MyBB