dongqun1656 2018-06-19 19:38
浏览 33

Bootstrap Modal不会使用PHP使用datepicker字段POST所有数据

I have two elements of members data such as id and some other info in a modal which are hidden input elements inside my modal, I bind data from a anchor tag using javascript, example of data element in the anchor tag:

data-column="'.htmlspecialchars($column, ENT_QUOTES, 'utf-8').'" 

Javascript example to bind into the modal:

$('#EnterExpiryModal').on('show.bs.modal', function (e) {
        var memberID = $(e.relatedTarget).data('id');
        $('#memID232').val(memberID);
        var cola3 = $(e.relatedTarget).data('column');
        $('#column3').val(cola3);
});

Having the relevant data for the members in question in my modal (modal code snippet below):

<div class="modal" id="EnterExpiryModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <div id="ExpiryError"></div>
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
          <h4 class="modal-title" id="myModalLabel">Please enter document expiry date</h4>
          <br>
            <form class="form-horizontal" method="post" id="ExpiryDateForm">
              <div class="form-group">
              <input id ="memID232" name="memID232" class="form-control" type="hidden">
              </div>

              <div class="form-group">
              <input id ="column3" name="column3" class="form-control" type="hidden">
              </div>

             <div class="form-group">
                  <label class="col-md-4 control-label">Date</label>
                  <div class="col-md-6  inputGroupContainer">
                    <div class="input-group">
                  <div class="clearfix">
                    <div id="date" data-placement="left" data-align="top" data-autoclose="true">
                      <input name="date" type="text" class="form-control hasDatepicker" placeholder="Choose Date">
                    </div>
                  </div>
                    </div>
                  </div>
              </div>

              <div class="middleme"><p><i class="fa fa-info-circle iwarner" aria-hidden="true"></i><small> These documents can be uploaded again at any time...</small></p></div>
              <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="submit" id="expirySubmit" name="expirySubmit" class="btn clocumsbtn">Confirm</button>
              </div>
            </form>
        </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>

The above code produces the below modal:

enter image description here

As you can see user is prompted to enter a expiry date in the form field and click confirm.

However the issue I am having is when I hit submit the form does submit, my jQuery validation does all the necessary checks before submitting using ajax, but my hidden input elements don't submit with the values as they should, they appear to be empty, but the datepicker (date) field is populated - I know the values populate with the required data I need.

Here's what the modal looks like without the elements being hidden:

enter image description here

Here is the validation:

$("#ExpiryDateForm").validate({
        rules:
              {


                memID232: {
                required: true,
                minlength: 0
                },

                column3: {
                required: true,
                minlength: 0
                },

                date: {
                required: true,
                minlength: 3
                }

        },
        messages:
        {
                memID232: "There's an error",
                column3: "There's an error",
                date: "Please enter the expiry date",

        },
        submitHandler: submitExpiryDate
});

here's the submit handler:

function submitExpiryDate() {
var data = $("#ExpiryDateForm").serialize();
$.ajax({
    type : 'POST',
    url : 'enterdocexpiry.php',
    data : data,

beforeSend: function() {
$("#expirySubmit").html('<span class="fa fa-spinner"></span>   please wait...');
},

success : function(responses) {

    if(responses=="1"){
        $('#ExpiryError').removeClass('animated shake');
        $("#ExpiryError").fadeIn(1000, function(){
        $('#ExpiryError').addClass('animated shake');
        $("#ExpiryError").html('<div class="alert alert-danger"> <span class="fa fa-exclamation"></span>   Sorry there was an error!</div>');
    });
    } 

    else if(responses=="updated"){
    $("#ExpiryError").fadeIn(2000, function(){
    $("#expirySubmit").html('<span class="fa fa-spinner"></span>   updating...');
    $("#ExpiryError").html("<div class='alert alert-success'><span class='fa fa-check-square-o'></span>  Added Expiry Date!</div>");
    setTimeout(function(){                          
       window.location.href="manage_docs.php";
    },2000);
    });
    }

    else {
        $("#ExpiryError").fadeIn(1000, function(){
        $("#ExpiryError").html('<div class="alert alert-danger"><span class="glyphicon glyphicon-info-sign"></span>   '+data+' !</div>');
        $("#expirySubmit").html('<span class="glyphicon glyphicon-log-in"></span>   Some other error');
    });
    }
}
});
return false;
}

here the php:

require "database.php";

$memberID = $_POST['memID232'];
$column = $_POST['column3'];

$date = DateTime::createFromFormat('d/m/Y',$_POST['dates']);
$expiryDate = $date->format("Y-m-d");

$docploaded = "Yes";

if (isset($_POST['expirySubmit'])) {

    if ($column == "passport") {

        $statement = $conn->prepare('UPDATE memberdocs SET pexpiry=:expiryDate,puploaded=:docploaded WHERE m_id=:memberID');
        $statement->bindParam(':expiryDate', $expiryDate);
        $statement->bindParam(':docploaded', $docploaded);    
        $statement->bindParam(':memberID', $memberID);
        $statement->execute();

        if($statement->execute() ):
        echo 'updated';
        else:
        echo "1";
        endif;

    }else if ($column == "crb") {

        $statement = $conn->prepare('UPDATE memberdocs SET cvexpiry=:expiryDate WHERE m_id=:memberID');
        $statement->bindParam(':expiryDate', $expiryDate);    
        $statement->bindParam(':memberID', $memberID);
        $statement->execute();

        if($statement->execute() ):
        echo 'updated';
        else:
        echo "1";
        endif;

    }

}

Now I have done some troubleshooting and it seems the datepicker is the issue here. If I remove the datepicker (date) form field and replace it with a standard free text input field my form submits successfully with the memID232 input field and column3 input field populated, executing my php script, I've tried to be as clear as possible I hope the screenshots and snippets help, any advice?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch