我是Codeigniter的新手,我已经完成了它的文档。我正在尝试提交一个HTML和jQuery的表单但是一旦我点击提交按钮没有任何反应,我的代码似乎没问题。我还有一个日期和时间选择器,我想问:我应该将两个存储在一个列中,日期和时间是什么类型?还是应该分开存放? 以下是我的观点:
<link href="<?php echo base_url() ?>assets/css/bootstrap-timepicker.min.css" rel="stylesheet">
<link href="<?php echo base_url() ?>assets/css/datepicker3.css" rel="stylesheet">
<link href="<?php echo base_url() ?>assets/tagsinput/bootstrap-tagsinput.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo base_url() ?>assets/js/bootstrap-timepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>assets/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>assets/js/typeahead.js/bloodhound.min.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>assets/js/typeahead.js/typeahead.bundle.min.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>assets/js/typeahead.js/typeahead.jquery.min.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>assets/tagsinput/bootstrap-tagsinput-angular.min.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>assets/tagsinput/bootstrap-tagsinput.min.js"></script>
<button class="btn btn-primary btn-xs pull-right" data-toggle="modal" data-target="#myModal">
Send Message
</button>
<style type="text/css">
.modal-backdrop{z-index: 1200;}
.modal{z-index: 1201;}
.tt-dropdown-menu{z-index: 1203; border: solid 1px #CCC; margin-right: 0; margin-left: 0; background-color: #fff; border-color: #ddd; border-width: 1px; border-radius: 4px 4px 0 0; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; -webkit-box-shadow: none; box-shadow: none;}
.tt-suggestions{}
</style>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="z-index: 9999;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Send Message</h4>
</div>
<div class="modal-body">
<form name="SendSMSForm" id="SendSMSForm" action="<?phpecho form_open('comments/create_comment'); ?>" class="form-horizontal" role="form" method="post">
<div class="form-group">
<label class="col-sm-2 control-label">Sender</label>
<div class="col-sm-10">
<p class="form-control-static"><label class="label label-primary">Inclusion</label></p>
</div>
</div>
<div class="form-group">
<label for="recepients" class="col-sm-2 control-label">To</label>
<div class="col-sm-10">
<input class="form-control" id="recepients" type="text" placeholder="" name="recepients" >
<p class="help-block">
<small>
Enter name of person/group in address-book E.g John, Family, Workmates
</small>
</p>
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" name="body" rows="3"></textarea>
</div>
</div>
<a data-toggle="collapse" data-parent="#accordion" href="#SendSMSOptions">
<span class="glyphicon glyphicon-plus"></span> Options
</a>
<div id="SendSMSOptions" class="panel-collapse collapse in">
<div class="panel-body">
<div class="form-group">
<label for="recepients" class="col-sm-2 control-label">Schedule Send</label>
<div class="col-sm-10">
<br />
<div class="input-group date">
<input data-provide="datepicker" name="datepicker" type="text" class="form-control"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
<div class="input-group bootstrap-timepicker">
<input id="timepicker" data-template="modal" name="timepicker" type="text" class="form-control">
<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="SendSMS">Send Now</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('.collapse').collapse();
$('#timepicker').timepicker({showMeridian: false, minuteStep: 15, defaultTime: 'current'});
$('.input-group.date').datepicker({
format: 'mm/dd/yyyy',
startDate: '-3d',
autoclose: true,
todayHighlight: true
});
$("#SendSMS").click(function () {
event.preventDefault();
var postData = $('#SendSMSForm').serializeArray();
$.post("<?php echo base_url('messages/send') ?>", postData)
.done(function (data) {
alert("Data Loaded: " + data);
});
});
});
var cities = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: '<?php echo base_url("c_contacts/index/cities") ?>'
});
cities.initialize();
var elt = $('#recepients');
elt.tagsinput({
tagClass: function(item) {
switch (item.continent) {
case 'Europe' :
return 'label label-primary';
case 'America' :
return 'label label-danger label-important';
case 'Australia':
return 'label label-success';
case 'Africa' :
return 'label label-default';
case 'Asia' :
return 'label label-warning';
}
},
itemValue: 'value',
itemText: 'text'
});
/*
elt.tagsinput('add', {"value": 1, "text": "Amsterdam", "continent": "Europe"});
elt.tagsinput('add', {"value": 4, "text": "Washington", "continent": "America"});
elt.tagsinput('add', {"value": 7, "text": "Sydney", "continent": "Australia"});
elt.tagsinput('add', {"value": 10, "text": "Beijing", "continent": "Asia"});
elt.tagsinput('add', {"value": 13, "text": "Cairo", "continent": "Africa"});
*/
elt.tagsinput('input').typeahead(null, {
name: 'cities',
displayKey: 'text',
source: cities.ttAdapter()
}).bind('typeahead:selected', $.proxy(function(obj, datum) {
this.tagsinput('add', datum);
this.tagsinput('input').typeahead('val', '');
}, elt));
});
</script>
答案 0 :(得分:0)
你的专栏:
<form name="SendSMSForm" id="SendSMSForm" action="<?phpecho form_open('comments/create_comment'); ?>" class="form-horizontal" role="form" method="post">
form_open
属性中不应包含action
。这只会产生以下结果:
<form name="SendSMSForm" id="SendSMSForm" action="<form action="http://localhost/comments/create_comment" method="post" accept-charset="utf-8">
" class="form-horizontal" role="form" method="post">
form_open()
是本机CI帮助程序,可帮助您生成form
标记。
https://www.codeigniter.com/userguide3/helpers/form_helper.html?highlight=form_open#form_open
这是正确的语法:
form_open($action = '', $attributes = array(), $hidden = array())
要创建form
代码,您应该这样做:
<!-- Remove the form tag and use CI's form helper -->
<?php echo form_open(NULL, array('name'=>'SendSMSForm', 'id'=>'SendSMSForm', 'class'=>'form-horizontal', 'role'=>'form')); ?>
这应该产生以下结果:
<form action="http://localhost/" name="SendSMSForm" id="SendSMSForm" class="form-horizontal" role="form" method="post" accept-charset="utf-8">
这是CodeIgniter方式。您仍然可以使用<form>
代码。