• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Radial Button Not Updating

#1
[eluser]riwakawd[/eluser]
When I click on my radial button "no". I should update value on database to "0" from "1", But does not I think it might be some thing to do with HTML code part. Rather than the model and or controller because it updates others fine.

Note: action form temporarily removed.

Code:
<form  method="post" enctype="multipart/form-data" id="form-setting" class="form-horizontal">

<ul class="nav nav-tabs" role="tablist" id="myTab">
   <li class="active"><a href="#tab-general" role="tab" data-toggle="tab">&lt;?php echo $tab_general;?&gt;</a></li>
   <li><a href="#tab-store" data-toggle="tab">&lt;?php echo $tab_store; ?&gt;</a></li>
</ul>

<div class="tab-content">

<div class="tab-pane" id="tab-server">

<div class="form-group">
<label class="col-sm-2 control-label">&lt;?php echo $entry_maintenance; ?&gt;</label>
<div class="col-sm-10">
<label class="radio-inline">
&lt;?php if ($config_maintenance) { ?&gt;
&lt;input type="radio" name="config_maintenance" value="1" checked="checked" /&gt;
&lt;?php echo $text_yes; ?&gt;
&lt;?php } else { ?&gt;
&lt;input type="radio" name="config_maintenance" value="1" /&gt;
&lt;?php echo $text_yes; ?&gt;
&lt;?php } ?&gt;
</label>
<label class="radio-inline">
&lt;?php if (!$config_maintenance) { ?&gt;
&lt;input type="radio" name="config_maintenance" value="0" checked="checked" /&gt;
&lt;?php echo $text_no; ?&gt;
&lt;?php } else { ?&gt;
&lt;input type="radio" name="config_maintenance" value="0" /&gt;
&lt;?php echo $text_no; ?&gt;
&lt;?php } ?&gt;
</label>
</div>
</div>

</div>

&lt;/form&gt;

Controller
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Setting extends MX_Controller {

public function __construct() {
parent::__construct();
$this->lang->load('admin/setting/setting', 'english');

$this->lang->load('admin/english', 'english');

if ($this->session->userdata('user_id') == true) {

  return true;

} else {

  redirect('admin');
}

}

public function index() {

$this->load->library('form_validation');

$this->form_validation->set_rules('config_name', 'Name');
$this->form_validation->set_rules('config_owner', 'Owner');
$this->form_validation->set_rules('config_address', 'Address');
$this->form_validation->set_rules('config_email', 'Email');
$this->form_validation->set_rules('config_telephone', 'Phone');

$this->document->setTitle($this->lang->line('heading_title'));

$data['heading_title'] = $this->lang->line('heading_title');

$data['action'] = site_url('admin/setting');

$data['logout'] = site_url('admin/logout');

$data['home'] = site_url('admin/dashboard');

$data['cancel'] = site_url('admin/dashboard');

$this->load->model('admin/setting/model_setting_store');

$config_meta_title = $this->model_setting_store->getSettings("config",'config_meta_title');

      if (!empty($config_meta_title)) {
         $data['config_meta_title'] = $config_meta_title[0]['value'];
      }

      $config_template = $this->model_setting_store->getSettings("config",'config_template');

      if (!empty($config_template)) {
         $data['config_template'] = $config_template[0]['value'];
      }
        
  $data['templates'] = array();

  $directories = glob(APPPATH . 'modules/catalog/views/theme/*', GLOB_ONLYDIR);

  foreach ($directories as $directory) {
   $data['templates'][] = basename($directory);
  }

  $config_maintenance = $this->model_setting_store->getSettings("config",'config_maintenance');

      if (!empty($config_maintenance)) {
         $data['config_maintenance'] = $config_maintenance[0]['value'];
  }

    if ($this->form_validation->run() == FALSE) {
    

     return $this->load->view('setting/settings', $data);

    } else {

     $config_meta_title = $this->input->post('config_meta_title');
         $this->model_setting_store->editSettings("config_meta_title", $config_meta_title);

     $config_maintenance = $this->input->post('config_maintenance');
         $this->model_setting_store->editSettings("config_maintenance", $config_maintenance);

       $config_template = $this->input->post('config_template');
         $this->model_setting_store->editSettings("config_template", $config_template);

     redirect('admin/dashboard');

    }

   }

}

Model

Code:
&lt;?php

class Model_setting_store extends CI_Model {

    function editSettings($key, $value) {
        if ($key && $value) {
            return $this->db->update('setting', array('value' => $value), array('key' => $key));
        } else {
            return false;
        }
    }


    function getSettings($group, $key) {
        if ($group && $key) {
            return $this->db->get_where('setting', array('group' => $group, 'key' => $key))->result_array();
        } else {
            return false;
        }
    }
    
   function get_config($key) {
      if ($key) {
            
      $data = $this->db->get_where('setting', array('group' => 'config', 'key' => $key))->result_array();
        
      if (!empty($data)) {
        
      return $data[0]['value'];
        
      } else {
        
      return false;
        
      }
        
      } else {
            
         return false;

      }
   }
    
    function set_key($key, $value) {
        $checkExitKey = $this->db->get_where('setting', array('group' => 'config', 'key' => $key))->result_array();
        if (!empty($checkExitKey)) {
            return $this->db->update('setting', array('value'=>$value), array('group' => 'config', 'key' => $key));    
        }else { //Insert
            $data = array(
                'website_id' => 0,
                'group' => 'config',
                'key' => $key,
                'value' => $value
            );
            return $this->db->insert('setting', $data);
        }
    }
}

#2
[eluser]riwakawd[/eluser]
Problem Fixed On Model

Code:
function editSettings($key, $value) {
        if ($key) {
            return $this->db->update('setting', array('value' => $value), array('key' => $key));
        } else {
            return false;
        }
    }

#3
[eluser]LuckyFella73[/eluser]
nice you fixed your problem. just a hint for repopulating
your type radio fileds:
Code:
// from the userguide:
&lt;input type="radio" name="myradio" value="1" &lt;?php echo set_radio('myradio', '1', TRUE); ?&gt; /&gt;
&lt;input type="radio" name="myradio" value="2" &lt;?php echo set_radio('myradio', '2'); ?&gt; /&gt;

The button getting TRUE as the 3rd param will be the selected one.
Details here (scroll down the whole page):
https://ellislab.com/codeigniter/user-gu...ation.html


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.