Welcome Guest, Not a member yet? Register   Sign In
checkbox = checked then enter = 1 otherwise value insert = 0
#1

[eluser]Rocky Mehta[/eluser]
My database field : 'free'=>'tinyint' bydefalult = 0
model page:
Code:
function insert_facility($filename)
{
$this->load->database();
$data = array(
  'venue_facilities_name' => $this->input->post('venue_facilities_name'),
  'venue_facilities_image'=> $filename,
  'free'    => $this->input->post('free'),
  'charg'   => $this->input->post('charg'),
  'bring'   => $this->input->post('bring')
  );
$this->db->insert('venue_facilities', $data);
}
function general()
{
$data['mvenue_facilities_id']['value'] = 0;
$data['venue_facilities_name'] = array('name'=>'venue_facilities_name','style'=>'width:250px');
$data['venue_facilities_image'] = array('name'=>'venue_facilities_image');
$data['free']   = array('name'=>'free','checked'=>TRUE);
$data['charg']   = array('name'=>'charg','checked'=>false);
$data['bring']   = array('name'=>'bring','checked'=>false);

return $data;
}
Controller page:
Code:
if ($this->input->post('save'))
{
if ($this->input->post('venue_facilities_id'))
{
  $this->venue_facilities_model->do_upload();
  $this->venue_facilities_model->update_facility($_FILES['userfile']['name']);
  echo "Data Updated Successfully";        redirect('http://localhost/venue/index.php/venue_facilities/update/');
}
else
{
  $this->venue_facilities_model->do_upload();
  $this->venue_facilities_model->insert_facility($_FILES['userfile']['name']);
         echo "Data Inserted Successfully";
}
}
i am insert the data the checkbox is not checked then enter bydefault = 0 but if i check the checkbox its also enter 0
can any one help how can i do the if check box is checked then enter in database value = 1.
#2

[eluser]InsiteFX[/eluser]
If a checkbox is not checked it will not return anything to you!

Trick for checkboxes:
Code:
<input type="hidden" name="box1" value="0" />
<input type="checkbox" name="box1" value="1" />

See how both input's are named - name=box1

#3

[eluser]Rocky Mehta[/eluser]
My database field : 'free'=>'tinyint' bydefalult = 0
model page:
Code:
function insert_facility($filename)
{
$this->load->database();
$data = array(
  'venue_facilities_name' => $this->input->post('venue_facilities_name'),
  'venue_facilities_image'=> $filename,
  'free'    => $this->input->post('free'),
  'charg'   => $this->input->post('charg'),
  'bring'   => $this->input->post('bring')
  );
$this->db->insert('venue_facilities', $data);
}
function general()
{
$data['mvenue_facilities_id']['value'] = 0;
$data['venue_facilities_name'] = array('name'=>'venue_facilities_name','style'=>'width:250px');
$data['venue_facilities_image'] = array('name'=>'venue_facilities_image');
$data['free']   = array('name'=>'free','checked'=>TRUE);
$data['charg']   = array('name'=>'charg','checked'=>false);
$data['bring']   = array('name'=>'bring','checked'=>false);

return $data;
}
Controller page:
Code:
if ($this->input->post('save'))
{
if ($this->input->post('venue_facilities_id'))
{
  $this->venue_facilities_model->do_upload();
  $this->venue_facilities_model->update_facility($_FILES['userfile']['name']);
  echo "Data Updated Successfully";        redirect('http://localhost/venue/index.php/venue_facilities/update/');
}
else
{
  $this->venue_facilities_model->do_upload();
  $this->venue_facilities_model->insert_facility($_FILES['userfile']['name']);
         echo "Data Inserted Successfully";
}
}
view page:
Code:
<tr>
  &lt;?php echo form_checkbox($free);?&gt;
</tr>
<tr>
&lt;?php echo form_checkbox($chrg);?&gt;
</tr>

i am insert the data the checkbox is not checked then enter bydefault = 0 but if i check the checkbox its also enter 0
can any one help how can i do the if check box is checked then enter in database value = 1.
if there are one then more checkboxes so how much hidden value takes and takes...
#4

[eluser]InsiteFX[/eluser]
The value is what holds if it is checked or not.
#5

[eluser]CroNiX[/eluser]
Code:
$value = $this->input->post('checkbox_field');
$checked = ($value === FALSE) ? 0 : 1;
#6

[eluser]Rocky Mehta[/eluser]
I m do this thing and it's work
Controller page:
Code:
if ($this->input->post('save'))
{
if ($this->input->post('venue_facilities_id'))
{
  $this->venue_facilities_model->do_upload();
  $this->venue_facilities_model->update_facility($_FILES['userfile']['name']);
  echo "Data Updated Successfully";
     redirect('http://localhost/venue/index.php/venue_facilities/update/');
}
else
{
  $this->venue_facilities_model->do_upload();//echo "hi";die;
  $post_free = $post_charg = $post_bring = '0';
  if(isset($_POST['free'])) {
   $post_free = '1';
}
         if(isset($_POST['charg'])) {
   $post_charg = '1';
         }
  if(isset($_POST['bring'])){
   $post_bring = '1';
  }
$this->venue_facilities_model->insert_facility($_FILES['userfile']['name'], $post_free, $post_charg, $post_bring);
  echo "Data Inserted Successfully";
}
}
Model page :
Code:
function insert_facility($filename,$post_free, $post_charg, $post_bring)
{
$this->load->database();
$data = array(
  'venue_facilities_name'   => $this->input->post('venue_facilities_name'),
  'venue_facilities_image'  => $filename,
  'free'        => $post_free,
  'charg'        => $post_charg,
  'bring'       => $post_bring
);
$this->db->insert('venue_facilities', $data);
}
i check my condition on controller page and pass the parameters and it's work.
sorry sir.

and thank x once again for help us.




Theme © iAndrew 2016 - Forum software by © MyBB