• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validation - Can someone explain this code?

#1
[eluser]The Wizard[/eluser]
Hello friends,

ive modified my code a little according to the validation tutorial series (7 screencasts) and now i have a question about a particular part in the code.

Code:
function setinfo ()
    {

//..

        $this->load->helper( 'form' );
        $this->load->helper( 'url' );
        $this->load->helper( 'language' );
        
        $form = array
        (
        
            'fields' => array
            (
            
                'name'                 => 'Name',
                'gender'             => 'Gender',
                'country_code'        => 'Country',
                'work'                 => 'Work',
                'birthday'             => 'Birthday',
                'city_living'         => 'City Living',
                'city_hometown'     => 'City Hometown'
            
            ),
            
            'rules' => array
            (
            
                'name'        => 'required',
                'gender'    => 'required',
                'country'    => 'required'
            
            )
        
        );

            $this->load->library('validation');
    
            $this->validation->set_rules( $form['rules'] );
            $this->validation->set_fields( $form['fields'] );
            
            
            if ($this->validation->run() == FALSE)
            {
                $data['theme_path']     = $this->theme_path;
                $data['theme_folder']    = $this->theme_folder;
                
                if ( $_SERVER["REQUEST_METHOD"] == 'POST' )
                {
                    $data['values'] = $_POST;
                    
                }
                else
                {
                    $user_info = $this->Model_user->User_GetUserInfo( $this->Model_user->Session_UserID() );
                    $data['values'] = $user_info;
                }
                
                $this->load->view( $this->theme_folder . 'master-info_edit.php', $data );            
            }
            else
            {
    

                $data['info-name']                = $this->input->post ('name');
                $data['info-city_living']        = $this->input->post ('city_living');
                $data['info-city_hometown']        = $this->input->post ('city_hometown');
                $data['country_code']            = $this->input->post ('country');
                $data['info-work']                = $this->input->post ('work');
                $data['info-birthday']            = $this->input->post ('birthday');
                $data['info-gender']            = $this->input->post ('gender');
    
                $user_id = $this->Model_user->Session_UserID();
                
                $info_result = $this->Model_user->User_SetUserInfo( $user_id, $data );
                
                redirect ( 'user/settings/success' );
            }                              
        

    }

and for the view part, when setting or better say, re populating forms,
we tend to use things like:
Code:
<?= form_input( 'name', $this->validation->name ) ?>

in this modified code i use:
Code:
<?= form_input( 'name', $values['name'] ) ?>

but as you may have noticed, i didnt use the first one in a fashion like
$this->validation->name to re-populate it.

So how come, this code actually works?

I would be more then happy if i can understand how this works.

Thanks in advance

#2
[eluser]Yash[/eluser]
xwero tells in some post there are three ways to call same thing

two way you already shown...

third..lemme search or xwero will help

#3
[eluser]The Wizard[/eluser]
would be cool Smile
besides, i looked at blogmer, looks very very promising,
cool man Smile

#4
[eluser]Yash[/eluser]
$_POST['some_field']

third one..

Thanks

#5
[eluser]manilodisan[/eluser]
This is how they get assigned inside the validation library:
Code:
foreach ( $_POST as $key => $value )
{
    $this->$key = $value;
}

'$this->validation->name' is already assigned when you call it in your form.

#6
[eluser]The Wizard[/eluser]
hmmmmmmmmmmmmmmmmm Smile

i see... thanks manilodisan


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.