I Have multicheckbox with input fields, where im inserting them into my database, but theres if i didint check and fill all inputs im not reciving values of that checked checkboxes
this is my view of checkboxes:
<!-- Form Name -->
<legend>Изберете типове за имота</legend>
<!-- Multiple Checkboxes (inline) -->
<div class="form-group">
<div class="col-md-4">
<label class="checkbox-inline" for="checkboxes-0">
<input type="checkbox" name="data[1][property_type_id]" id="checkboxes-0" value="22">
Пентхаус
</label>
<br>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="cena" name="data[1][alt_txt]" type="text" placeholder="Въведи цена" class="form-control input-md">
</div>
</div>
<label class="checkbox-inline" for="checkboxes-1">
<input type="checkbox" name="data[2][property_type_id]" id="checkboxes-1" value="21">
Гараж/Паркомясто
</label>
<br>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="cena" name="data[2][alt_txt]" type="text" placeholder="Въведи цена" class="form-control input-md">
</div>
</div>
<label class="checkbox-inline" for="checkboxes-2">
<input type="checkbox" name="data[3][property_type_id]" id="checkboxes-2" value="20">
Бизнес
</label>
<br>
<div class="form-group">
<div class="col-md-8">
<input id="cena" name="data[3][alt_txt]" type="text" placeholder="Въведи цена" class="form-control input-md">
</div>
</div>
and this is my model where im inserting my checkboxes into table:
public function save_dynamic($data, $id)
{
// Delete all
$this->db->where('property_id', $id);
$this->db->where('value !=', 'SKIP_ON_EMPTY');
$this->db->delete('property_value');
// Insert all
$insert_batch = array();
// Process the POST DATA from the FORM
foreach($data as $key=>$value)
{
// Do this if the key is called option
if(substr($key, 0, 6) == 'option')
{
$pos = strpos($key, '_');
$option_id = substr($key, 6, $pos-6);
$language_id = substr($key, $pos+1);
$val_numeric = NULL;
if( is_numeric($value) )
{
$val_numeric = intval($value);
}
$insert_arr = array('language_id' => $language_id,
'property_id' => $id,
'option_id' => $option_id,
'value' => $value,
'value_num' => $val_numeric);
if($value != 'SKIP_ON_EMPTY')
$insert_batch[] = $insert_arr;
}
}
$data=$this->input->post('data');
if(count($insert_batch) > 0) {
$this->db->insert_batch('property_value', $insert_batch);
}
// We need to loop through each entry and add in the property_id
$insert_array = array();
$property_id = array('property_id'=>$id);
foreach($data as $array){
$insert_array[] = array_merge($array,$property_id);
}
if($this->db->affected_rows() > 0) {
$this->db->insert_batch('property_type_details', $insert_array);
echo $this->db->last_query();
}
my array looks like
array(20) {
[0]=>
array(3) {
["property_type_id"]=>
string(2) "22"
["alt_txt"]=>
string(5) "25.22"
["property_id"]=>
int(182)
}
[1]=>
array(3) {
["property_type_id"]=>
string(2) "21"
["alt_txt"]=>
string(5) "30.10"
["property_id"]=>
int(182)
}
[2]=>
array(3) {
["property_type_id"]=>
string(2) "20"
["alt_txt"]=>
string(2) "25"
["property_id"]=>
int(182)
}
and this is what im getting if i didnt fill and check any checkbox
INSERT INTO `property_type_details` () VALUES ('25.22',183,'22'), ('30.10',183,'21')
Aucun commentaire:
Enregistrer un commentaire