Welcome Guest, Not a member yet? Register   Sign In
Form validation
#1

[eluser]julgus[/eluser]
How can I check if the current field in my view has a validation rule?

I would like to check the validation rule for each an every field in my view and if a rule exists I can automatically show this using a style class for the field.

Best regards
Johan
#2

[eluser]pistolPete[/eluser]
Why don't you "hard code" the css into the view?
Your validation rules should't change, so is there a reason to do this dynamically?

Anyway, you can access the validation rules using:
Code:
$this->form_validation->_field_data['field_name']['rules']
#3

[eluser]julgus[/eluser]
Thanks,
I use the same form in a document process and depending on status I need different validations rules.

The code you suggested just shows an empty array...

regards

[quote author="pistolPete" date="1235659524"]Why don't you "hard code" the css into the view?
Your validation rules should't change, so is there a reason to do this dynamically?

Anyway, you can access the validation rules using:
Code:
$this->form_validation->_field_data['field_name']['rules']
[/quote]
#4

[eluser]pistolPete[/eluser]
Quote:The code you suggested just shows an empty array…
I just had a look at class CI_Form_validation and saw that the rules are only set if $_POST isn't empty:
Code:
function set_rules($field, $label = '', $rules = '')
{
        // No reason to set rules if we have no POST data
        if (count($_POST) == 0)
        {
            return;
        }
(...)

Either extend CI_Form_validation or additionally save the rules in your controller and pass them to the view.




Theme © iAndrew 2016 - Forum software by © MyBB