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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)