dousi2251 2017-07-27 19:33
浏览 37
已采纳

如何调用PHP函数将数据从Modal弹出窗口上传到数据库? [关闭]

I want to upload data entered in Modal popup into Database. The php code to upload the data is written in function named "Add()". The question is how do I call this function on clicking the submit button of Modal popup.

Modal Popup Code:

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content" style="padding:15px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Please fill your details...</h4>
            </div>
            <div class="modal-body" style="background-color:#ededed;padding:20px;">
                <form method="post" action="details.php" id="form_login" style="padding:20px;" enctype="multipart/form-data">
                    <div class="form-group">
                        <label>Name: </label>
                        <div class="input-group">
                            <input type="text" class="form-control" name="user" placeholder="Name..." required="">
                            <label for="uLogin" class="input-group-addon glyphicon glyphicon-user" style="background-color:#337ab7;color:white;"></label>
                        </div>
                    </div> <!-- /.form-group -->
                    <label>Phone number: </label>
                    <div class="form-group">
                        <div class="input-group">
                            <input type="number" class="form-control" name="phone" placeholder="Mobile number..." required="">
                            <label for="uPassword" class="input-group-addon glyphicon glyphicon-phone" style="background-color:#337ab7;color:white;"></label>
                        </div> <!-- /.input-group -->
                    </div> <!-- /.form-group -->
                    <label>Email Id:</label>
                    <div class="form-group">
                        <div class="input-group">
                            <input type="email" class="form-control" name="email" placeholder="Email Id..." required="">
                            <label for="uPassword" class="input-group-addon glyphicon glyphicon-envelope" style="background-color:#337ab7;color:white;"></label>
                        </div> <!-- /.input-group -->
                    </div> <!-- /.checkbox -->
            </div> <!-- /.modal-body -->
            <div class="modal-footer">
                <button type="submit" class="btn btn-success " id="buyer_details" name="buyer_details" data-dismiss="modal">Submit Details</button>
            </div>
            </form>
        </div>
    </div>
</div>  
  • 写回答

3条回答 默认 最新

  • donglvhe7591 2017-07-27 19:56
    关注

    Use ajax on that something like this

    add a script on your page and set your modal to submit id to function with two parameters as add and id of your form, this code can be used as add edit and delete..

    function userAction(type,id){
        //id = (typeof id == "undefined")?'':id;
        var statusArr = {add:"added",edit:"updated",delete:"deleted"};
        var userData = '';
        if (type == 'add') {
            userData = $("#addForm").find('.form').serialize()+'&action_type='+type+'&id=';
        }else if (type == 'edit'){
            userData = $("#editForm").find('.form').serialize()+'&action_type='+type;
        }else{
            userData = 'action_type='+type+'&id='+id;
        }
        $.ajax({
            type: 'POST',
            url: 'action.php',
            data: userData,
            success:function(msg){
                if(msg == 'ok'){
                    //alert('Patient data has been '+statusArr[type]+' successfully.');
                    var notif;
                    var r = confirm('Patient data has been '+statusArr[type]+' successfully. Reload?');
                    if (r == true) {
                        location.reload();
                        //notif = "You pressed OK!";
                    } else {
                        $('#myModal').modal('hide');
                        //notif = "You pressed Cancel!";
                    }
    
                }else{
                    alert('Some problem occurred, please try again.');
                }
            }
        });
    }
    

    then catch your post on your action.php something like this

    if($_POST['action_type'] == 'add'){        
            $login= $_POST['login'],
            $email = $_POST['email'],
            $password = $_POST['password'], 
    }
    

    I hope the next steps are good to you inserting the data to database Still, work on your code.. show us what you have so far.. ^_^

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制