Welcome Guest, Not a member yet? Register   Sign In
Form validation and re-population - Not Working
#1

[eluser]jaswinder_rana[/eluser]
Code
Code:
//Edit User Profile
    function user_profile()
    {
        if ($this->dx_auth->is_logged_in())
        {
            $this->load->library('Validation');
            $this->_validation_profile();
            
            if ($this->validation->run() !== FALSE){
                $data['user_id'] = $this->dx_auth->get_user_id();
                $data['id_country'] = $this->input->post('id_country');
                $data['website'] = $this->input->post('website');
                
                
            }else{
                //get User Profile data from database
                   $query = $this->user_profile->get_profile($this->dx_auth->get_user_id());
                $obj = $query->result();
                        
                $data['id_country'] = $obj[0]->id_country;
                $data['website'] = $obj[0]->website;
            }
            $data['countries'] = $this->_get_countries();
            $this->load->view('auth/user_profile',$data);
        }
    }
// --------------------------------------------------------------------

    function _validation_profile()
    {
        
        $rules['id_country'] = 'required|numeric';//'trim|required|htmlspecialchars|max_length[12]|alpha_dash';
        $rules['website'] = 'trim|htmlspecialchars';//'trim|htmlspecialchars|callback_dateIssued';
        $this->validation->set_rules($rules);
    
        $fields['id_country'] = $this->lang->line('site_id_country');
        $fields['website'] = $this->lang->line('site_website');
        $this->validation->set_fields($fields);

        $this->validation->set_error_delimiters('<span class="error">', '</span>');
    }

Then my form is (Not sure if I am doing it the proper way

Code:
&lt;?php $this->load->view('header');?&gt;
&lt;?php
    if(!$this->dx_auth->is_logged_in()){
        redirect('');
    }

$id_country =  set_value('id_country',$id_country);


$arr = array();
foreach($countries as $key=>$value){
    $arr[$value->id] = $value->name;
}


$website = array(
    'name'    => 'website',
    'id'    => 'website',
    'size'    => 50,
    'value' => set_value('website',$website)
);

?&gt;
<h1>&lt;?php echo $this->lang->line('site_user_profile');?&gt;</h1>
<fieldset>
<legend>User Profile</legend>
&lt;?php echo form_open('auth/user_profile'); ?&gt;

&lt;?php echo $this->dx_auth->get_auth_error(); ?&gt;

<dl>
    <dt>&lt;?php echo form_label('Country', 'country'); ?&gt;</dt>
    <dd>
        &lt;?php echo form_dropdown('id_country',$arr,$id_country); ?&gt;
        &lt;?php echo form_error('id_country'); ?&gt;
    </dd>

    <dt>&lt;?php echo form_label('Website', $website['id']); ?&gt;</dt>
    <dd>
        &lt;?php echo form_input($website); ?&gt;
        &lt;?php echo form_error($website['name']); ?&gt;
    </dd>

    
    <dt></dt>
    <dd>&lt;?php echo form_submit('update', 'Update Profile'); ?&gt;</dd>
</dl>

&lt;?php echo form_close(); ?&gt;
</fieldset>

&lt;?php $this->load->view('footer');?&gt;

It's populating because I am using $this->input->post(). If I try to do an echo on top of my view, it doesn't work.

Code:
echo set_value('id_country');


Thanks


Messages In This Thread
Form validation and re-population - Not Working - by El Forum - 12-21-2008, 06:11 PM
Form validation and re-population - Not Working - by El Forum - 12-21-2008, 11:11 PM
Form validation and re-population - Not Working - by El Forum - 12-22-2008, 10:52 AM
Form validation and re-population - Not Working - by El Forum - 12-22-2008, 11:46 AM
Form validation and re-population - Not Working - by El Forum - 12-22-2008, 11:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB