Welcome Guest, Not a member yet? Register   Sign In
Extended form validation and blank fields
#3

[eluser]urrmurrmur[/eluser]
Sure thing, here's the config file:

Code:
<?php

$config = array(
    
    'user/update_user_info' => array(
        array(
            'field' => 'firstname',
            'label' => 'Voornaam',
            'rules' => 'lamosaurus'
        ),
        array(
            'field' => 'lastname',
            'label' => 'Naam',
            'rules' => 'required'
        ),
        array(
            'field' => 'email',
            'label' => 'E-mail',
            'rules' => 'required|valid_email'
        ),
        array(
            'field' => 'params[]',
            'label' => 'Parameter',
            'rules' => 'required|array_has_values'
        )
    )
    
    //Add new validation
);

It's the first field, and as you can see, I don't test required. If I do test required as well ('required|lamosaurus', as you posted) required runs whether the field is blank or not. If required doesn't pass, it doesn't test lamosaurus (as expected), but if required passes, it doesn't test it either.

What I find strangest is that everything works as expected when I do it as a callback function - but I don't like the callback principle, extending is much cleaner.


By the way, the final field params[] also uses a validation function I've written (array_has_values), which behaves in the exact same way as lamosaurus.


EDIT: In case it's of any use, here is the user/update_user_info function.

Code:
function update_user_info()
    {    
        if( $this->form_validation->run() )
        {
            //Get relevant data from POST and SESSION
            $firstname =     $this->input->post('firstname');
            $lastname =     $this->input->post('lastname');
            $email =         $this->input->post('email');
            $occupation =     $this->input->post('occupation');
            $params =         $this->input->post('params');
            $id =             $this->session->userdata('id');
            
            //Update general info in the user table
            $this->user_model->update_account_data( $id, $firstname, $lastname, $email );
            
            //Insert profile info into the profile table
            $this->profile_model->insert_profile_data( $id, $params );
            
            //Send the user to step 2 in the profile creation process
            $body_data['races'] = $this->flock_model->get_races();
            $body_data['housing_systems'] = $this->flock_model->get_housing_systems();
            $body_data['create_profile_step'] = CREATE_FARMPROFILE_VIEW_STEP2;
            
            $this->load_page(CREATE_FARMPROFILE_VIEW, $body_data);
        }
        else
        {
            $subtype = $this->session->userdata('subtype');
            $this->load_create_profile( $subtype );
        }
    }


Messages In This Thread
Extended form validation and blank fields - by El Forum - 06-04-2010, 05:23 AM
Extended form validation and blank fields - by El Forum - 06-04-2010, 07:05 AM
Extended form validation and blank fields - by El Forum - 06-04-2010, 08:45 AM
Extended form validation and blank fields - by El Forum - 06-09-2010, 02:52 AM
Extended form validation and blank fields - by El Forum - 06-09-2010, 03:07 AM
Extended form validation and blank fields - by El Forum - 06-14-2010, 07:44 AM
Extended form validation and blank fields - by El Forum - 06-14-2010, 08:49 AM
Extended form validation and blank fields - by El Forum - 06-17-2010, 05:51 AM
Extended form validation and blank fields - by El Forum - 06-17-2010, 06:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB