Welcome Guest, Not a member yet? Register   Sign In
Trying to understand forms
#1

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
Reply
#2

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.
Reply
#3

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.
Reply
#4

You cannot have 2 keys with the same name in your array, the last key will over write the first key.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB