[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