这是jquery代码,除了DistrictId,InstituteId和ComplainType之外,所有字段名都是检索到的每个元素的准确值。这些都是选择框值
使用jquery和html格式的索引文件,只检索selece框的值
$(document).ready(function() {
$("body").on('click', '#SaveComplain', function() {
var date = new Date();
var n = date.toDateString();
var t = date.toLocaleTimeString();
var time = n + ' ' + time;
var FocalPerson = $('#FocalPerson').val();
var Email = $('#Email').val();
var ContactNumber = $('#ContactNumber').val();
var InstituteId = $('#Institute').val();
var ComplainDate = time;
var ComplainStatus = 'Registered';
var ComplaintDetails = $('#ComplaintDetails').val();
var ComplaintType = $('#ComplaintType').val();
var DistrictId = $('#District').val();
$.ajax({
type: 'POST',
dataType: 'html',
data: ('FocalPerson=' + FocalPerson + 'Email=' + Email + '&ContactNumber=' + ContactNumber + '&InstituteId=' + InstituteId + '&ComplainDate=' + ComplainDate + '&ComplainStatus=' + ComplainStatus + '&ComplaintDetails=' + ComplaintDetails + '&ComplaintType=' + ComplaintType + '&DistrictId=' + DistrictId),
url: "<?php echo base_url('TicketSupport/SaveComplain'); ?>",
redirect: true,
success: function(response) {
$('#msg').html('Complain Registered Successfully <br> Soon You will be Contacted by the Concerned Department');
}
});
});
});
<div class="tab-content">
<div class="tab-pane active" id="formcontrols">
<form name="form" method="post" action="<?php echo
base_url('TicketSupport/SaveComplain'); ?>" class="form-horizontal">
<fieldset>
<div class="control-group">
<div class="controls">
<?php echo $this->session->flashdata('record_added'); ?>
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="control-group">
<label class="control-label" for="lastname">District:</label>
<div class="controls">
<select class="form-control span3" name="District" id="District" required="required">
<option value="">Select District</option>
<?php
foreach ($AllDistricts as $AllDistrict) {
?>
<option value="<?php echo $AllDistrict['DistrictId']; ?>"> <?php echo $AllDistrict['DistrictName']; ?></option>
<?php
}
?>
</select>
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="control-group">
<label class="control-label" for="email">Institute:</label>
<div class="controls">
<div id="InstituteList">
<select class="form-control span3" name="Institute" id="Institute" required="required">
<option value="0">Select Institute </option>
</select>
</div>
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="control-group">
<label class="control-label" for="complaintype">Complain Type</label>
<div class="controls">
<select class="form-control span3" name="ComplaintType" id="ComplaintType" required="required">
<option value="Finger Print Issue">Finger Print Issue</option>
<option value="Device Problem"> Device Issue</option>
<option value="Internet Connectivity Issue">Internet Connectivity Issue</option>
<option value="Other"> Other</option>
</select>
<textarea id="other" class="form-control" name="ComplaintType" placeholder="Describe Issue" style="display: none;" rows="3"></textarea>
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="control-group">
<label class="control-label" for="username">Name:</label>
<div class="controls">
<input type="text" class="span3" id="FocalPerson" name="FocalPerson" required="required" placeholder="Enter Your Name">
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="control-group">
<label class="control-label" for="username">Email:</label>
<div class="controls">
<input type="text" class="span3" id="Email" name="Email" required="required" placeholder="Enter Your Email">
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="control-group">
<label class="control-label" for="contactnumber">Contact Number:</label>
<div class="controls">
<input type="text" class="span3" id="ContactNumber" name="ContactNumber" required="required" placeholder="Enter Contact Number">
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="control-group">
<label class="control-label" for="complaindetails">Details</label>
<div class="controls">
<textarea class="form-control span6" rows="5" name="ComplaintDetails" id="ComplaintDetails" required="required"></textarea>
</div> <!-- /controls -->
</div> <!-- /control-group -->
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Submit" name="SaveComplain" id="SaveComplain">
<input type="reset" class="btn" value="Reset" >
</div> <!-- /form-actions -->
</fieldset>
这是我的控制器文件
public function SaveComplain(){
$Record = array(
'FocalPerson' => $this->input->post('FocalPerson'),
'Email' => $this->input->post('Email'),
'ContactNumber' => $this->input->post('ContactNumber'),
'InstituteId' => $this->input->post('InstituteId'),
'ComplainDate' => date('Y-m-d H:i:s'),
'ComplainStatus' => 'Registered',
'ComplainDetail' => $this->input->post('ComplaintDetails'),
'ComplainType' => $this->input->post('ComplaintType'),
'DistrictId' => $this->input->post('DistrictId'),
);
print_r($Record);
die();
那就是结果
Array ( [FocalPerson] => someone [Email] => someone@mail.com [ContactNumber] => 123456789 [InstituteId] => [ComplainDate] => 2017-12-21 07:08:24 [ComplainStatus] => Registered [ComplainDetail] => this is complain detail [ComplainType] => [DistrictId] => )