[eluser]Judgestar[/eluser]
Hi there I should start of by saying I am new to php coding and have learned alot from these forums. I am having an issue with multiple checkbox $_POST data not being sent to my submit button to process the data and hoping a fresh pair of eyes could point to what I might be doing wrong. Ignore some of the commented out code that is me trying to get it to work using a loop.
The view I have works with the checkbox if I were to select one box but not multiple, so I can select any checkbox individually and it works perfectly but not if I try to select multiple checkboxes.
Here is the view for my form:
Code:
<div id='content-main'>
<div id='task'>
<table>
<tr>
<th>RequestID</th>
<th>Submitted</th>
<th>Submitted By</th>
<th>Agent</th>
<th>Billing Sys</th>
<th>Product</th>
<th>Add/Rem</th>
<th>Comment</th>
</tr>
<?php if(!empty($requests)): ?>
<?php foreach($requests as $r): ?>
<?php form_open('skills/manage');
/*$RequestedID = array(
'name' => 'SkillRequests',
'id' => $r->RequestID,
'value' => $r->RequestID,
'checked' => FALSE
);*/
?>
<tr>
<td class="title-short"><?php echo anchor('skills/updateSkill/'.$r->RequestID.'', $r->RequestID); ?><?php echo form_checkbox($r->RequestID,$r->RequestID); ?></td>
<td class="title-short"><?php echo !empty($r->CreatedDate) ? date('D m-d-y', strtotime($r->CreatedDate)) : 'N/A'; ?></td>
<td class="title-short"><?php echo $r->Supervisor; ?></td>
<td class="title-short"><?php echo $r->Name; ?></td>
<td class="title-short"><?php echo $r->BillingSys; ?></td>
<td class="title-short"><?php echo $r->Product; ?></td>
<td class="title-short"><?php echo $r->AddRem; ?></td>
<td class="title-short"><?php echo $r->RequestDescription; ?></td>
<?php echo form_close(); ?>
<!--<?php echo var_dump($RequestedID); ?>-->
<?php endforeach; ?>
<!--<?php $rids = array($_POST[$data]); ?>
<?php foreach($rids as $r2): ?>-->
<?php echo form_open('skills/updateSkill/'.$r->RequestID.''); ?>
<?php echo form_submit('Approve', 'Approve'); ?>
<?php echo form_open('skills/updateSkill/'.$r->RequestID.''); ?>
<?php echo form_submit('Deny', 'Deny'); ?>
<?php echo form_close(); ?>
<!--<?php endforeach; ?>-->
<?php endif; ?>
</table>
<?php echo form_open('skills/updateSkill/'.$r->RequestID.''); ?>
<?php echo form_submit('Approve', 'Approve'); ?>
<?php echo form_open('skills/updateSkill/'.$r->RequestID.''); ?>
<?php echo form_submit('Deny', 'Deny'); ?>
<?php echo form_close(); ?>
</div>
</div>
Here is my model for this view:
Code:
function getRequest($options = array())
{
where_fields(array('RequestID', 'RequestStatus', 'CreatedBy', 'ID'), $options);
$this->db->order_by('RequestID', 'ASC');
$query = $this->db->get('SkillRequestID');
if($query->num_rows() > 0)
{
if(isset($options['RequestID']))
{
return $query->row();
}
return $query->result();
}
return false;
} // END function
function updateSkills($options = array())
{
foreach($_POST[$options] as $option)
{
$sql = "Update AgentSkills set ";
if($option['BillingSys'] == 'trac')
{
$sql .= "T";
} elseif($option['BillingSys'] == 'AC')
{
$sql .= "A";
}
switch($option['Product'])
{
case 'NET':
$sql .= "NET = ";
break;
case 'CEL':
$sql .= "CEL = ";
break;
case 'Video':
$sql .= "Video = ";
break;
default:
break;
}
if($option['AddRem'] == 'Add')
{
$sql .= "1";
} elseif($option['AddRem'] == 'Rem')
{
$sql .= "0";
}
$sql .= " where ID = {$option['ID']}";
$this->db->query($sql);
$this->approveRequest($option['RequestID']);
}
} // END function
function denyRequest($options = array())
{
$this->db->set('RequestStatus', 'Denied');
$this->db->where('RequestID', $options['RequestID']);
$this->db->update('AgentSkillRequest');
return $this->db->affected_rows();
} // END function
and this is my controller for this page:
Code:
function updateSkill($id=0)
{
if(!$this->session->userdata('Manager') == 1 && !$this->session->userdata('Project') == 1)
{
redirect('skills');
}
$data = array();
$this->load->model('skill_model');
$data['r'] = $this->skill_model->getRequest(array('RequestID' => $id));
if(isset($_POST['Approve']))
{
$options = array(
'BillingSys' => $data['r']->BillingSys,
'Product' => $data['r']->Product,
'AddRem' => $data['r']->AddRem,
'ID' => $data['r']->ID,
'RequestID' => $id
);
$this->skill_model->updateSkills($options);
redirect('skills/manageRequest');
}
if(isset($_POST['Deny']))
{
$options = array(
'RequestID' => $id
);
$this->skill_model->denyRequest($options);
redirect('skills/manageRequest');
}
$this->load->view('template/header', $data);
$this->load->view('skills/detail', $data);
$this->load->view('template/footer', $data);
}
like I said it works when I select one checkbox but not multiples, I tried a few loops and they did not work for me (probably did not do it correctly) as I said still new to php and codeigniter. Thanks for any help that is given.