CodeIgniter Forums
Trying to understand forms - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Trying to understand forms (/showthread.php?tid=64544)



Trying to understand forms - doomie22 - 03-02-2016

Hi all,

I feel I am so close to getting my first form to work, I just cannot understand how to process what is setup.  I have the following:

PHP Code:
<?php echo form_open('login/settings'); ?>
        <?php echo form_label('Google Analytics :'); ?>
        <?php echo form_input(array('id' => 'google-analytics''name' => 'google-analytics''class' => 'form-control''value' => $google->setting_value)); ?><br />
        <?php echo form_label('Hotjar Analytics :'); ?>
        <?php echo form_input(array('id' => 'hotjar-analytics''name' => 'hotjar-analytics''class' => 'form-control''value' => $hotjar->setting_value)); ?>
        <br /><?php echo form_submit(array('id' => 'submit''value' => 'Submit''class' => 'btn btn-default8')); ?>
        <?php echo form_close(); ?>

I get no errors and when I hit submit it flashes the screen so I believe it's working but I just cannot figure out how to get it to process what is in this form, I have been looking through the docs and its just not sinking in.

Can anyone help please?

Thanks,
Doomie


RE: Trying to understand forms - skunkbad - 03-02-2016

The next step would be to use the Form Validation library to process the posted values. You then have the values available with set_value(), and you can do whatever you want with them.


RE: Trying to understand forms - doomie22 - 03-03-2016

Ok I have managed to get to this stage but I am stuck at only being able to update 1 item (there is 2).  

I have this in my controller:

PHP Code:
public function process(){
 
           
            
            $data 
= array(
 
           
            
'setting_value' => $this->input->post('google-analytics'),
 
           'setting_value' => $this->input->post('hotjar-analytics')
 
           );
 
           //Transfering data to Model
 
           $this->Admin_model->form_insert($data);
 
           redirect('login/settings');
 
       

and in the model I have :

PHP Code:
function form_insert($data){
 
      $this->db->where('id'1);
 
      $this->db->update('settings'$data);
 
      
   



Now I know that this just updates it and then puts the 2nd one into the first value as I am hard coding id=1, I just cannot figure out how I can tell it to put it into the different id's.


RE: Trying to understand forms - InsiteFX - 03-03-2016

You cannot have 2 keys with the same name in your array, the last key will over write the first key.