Welcome Guest, Not a member yet? Register   Sign In
need autofill function in view
#1

I have some text boxes in my view like this:
<?=form_input(['name'=>'last_name','type'=>'text','style'=>'text-transform:capitalize','class'=>'form-control','placeholder'=>'Enter your last name','value'=>set_value('last_name')])?>
i have a database table 'userlogin' which has a field  'last_name'
when I am entering the value in the last_name field, i want autofill function in it with all the values from 'last_name' field in database. How do i do this?
Reply
#2

The easiest way is to gather all the field data you need in the controller and then pass it to the view.

Assuming the controller calls a model that returns a $user_data object like this

PHP Code:
$data['first_name'] = $user_data->first_name;
$data['last_name'] = $user_data->last_name;
$this->load->view("some_view"$data); 

Then in the view
PHP Code:
<?= form_input([
 
   'name' => 'first_name',
 
   'type' => 'text',
 
   'style' => 'text-transform:capitalize',
 
   'class' => 'form-control',
 
   'placeholder' => 'Enter your first name'], 
 
   'value' => set_value('first_name'$first_name)]); 
?>

Use the same idea for the last_name field.
PHP Code:
<?= form_input([
 
   'name' => 'last_name',
 
   'type' => 'text',
 
   'style' => 'text-transform:capitalize',
 
   'class' => 'form-control',
 
   'placeholder' => 'Enter your last name'], 
 
   'value' => set_value('last_name'$last_name)]);
?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB