Welcome Guest, Not a member yet? Register   Sign In
form_validation: Re-populating field without rules
#11

[eluser]Mirage[/eluser]
@haydenp

Boy - that is hackish, but certainly a general solution. I'm torn between amending the form_validation class, putting this in my controllers, or simply adding rules to my config (even though I hate that)...

-m
#12

[eluser]Mirage[/eluser]
[quote author="xwero" date="1244748429"]I like following simple function to repopulate form fields
Code:
function value_field($field,$default='')
{
   return (isset($_POST[$field])) ? $_POST[$field] : $default ;
}
No messing around with validation rules.[/quote]

Agree with this. Although the whole point of the form_validation class and helpers is NOT to have to do that.

-m
#13

[eluser]zedd45[/eluser]
[quote author="xwero" date="1244748429"]I like following simple function to repopulate form fields
Code:
function value_field($field,$default='')
{
   return (isset($_POST[$field])) ? $_POST[$field] : $default ;
}
No messing around with validation rules.[/quote]


I really like this solution. I wonder if this is more CI friendly, though:

function field_value($field,$default='') {
$CI =& get_instance();
$value = $CI->input->get_post($field, true);
return false === $value || '' === $value ? $default : $value;
}


This way you tie into CI's native Input class.

you could use post instead of get_post if you were not concerned with GET[];




Theme © iAndrew 2016 - Forum software by © MyBB