dpfl37651 2018-02-11 18:53
浏览 55
已采纳

提交表格时没有任何反应

I am new in Codeigniter and I have gone through its documentation. I'm trying to submit a form which is in HTML and jQuery but once I click the submit button nothing happens and my code seems fine. I also have a date and time picker which I would like to ask: should I store both in one column with a date and time as its type? or should they be stored separately? Here is my view:

<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">&times;</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>

</div>
  • 写回答

1条回答 默认 最新

  • dr6673999 2018-02-12 02:02
    关注

    Your line:

    <form name="SendSMSForm" id="SendSMSForm" action="<?phpecho form_open('comments/create_comment'); ?>" class="form-horizontal" role="form" method="post">
    

    should not have form_open in action attribute. This will only generate the following:

        <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() is a native CI helper and helps you generate a form tag. https://www.codeigniter.com/userguide3/helpers/form_helper.html?highlight=form_open#form_open

    Here's the proper syntax:

    form_open($action = '', $attributes = array(), $hidden = array())
    

    To create a form tag, you should do this:

    <!-- 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')); ?>
    

    This should generate the following:

    <form action="http://localhost/" name="SendSMSForm" id="SendSMSForm" class="form-horizontal" role="form" method="post" accept-charset="utf-8">
    

    This is a CodeIgniter way. You can still use the <form> tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)