Codeigniter $ this-> input-> post()对于提交输入为空

问题描述 投票:0回答:1
<form method="post" id="user_form">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Add User</h4>
            </div>
            <div class="modal-body">
                <label>Enter First Name</label>
                <input type="text" name="first_name" id="first_name" class="form-control" />
                <br />
                <label>Enter Last Name</label>
                <input type="text" name="last_name" id="last_name" class="form-control" />
                <br />
                <label>Select User Image</label>
                <input type="file" name="user_image" id="user_image" />
                <span id="user_uploaded_image"></span>
            </div>
            <div class="modal-footer">
                <input type="hidden" name="user_id" id="user_id" />
                <input type="submit" name="action" id="action" class="btn btn-success" value="Add" />
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </form>

和此视图中的脚本:

$.ajax({
                    url:"<?php echo base_url() . 'raportowanie/user_action'?>",
                    method:'POST',
                    data:new FormData(this),
                    contentType:false,
                    processData:false,
                    success:function(data)
                    {
                        alert(data);
                        $('#user_form')[0].reset();
                        $('#userModal').modal('hide');
                        dataTable.ajax.reload();
                    }
                });

在控制器中

    function user_action(){

    echo 'Action is: '.$this->input->post('action');
}

问题是$ this-> input-> post('action')不返回值输入。如果我更改文本的输入类型,则此$ this-> input-> post('action')可以,返回值= Add。为什么这对输入type =“ submit”不起作用?我如何获得输入的价值。请帮助。

php codeigniter post input submit
1个回答
0
投票
提交输入类型仅用于提交所有表单值的提交按钮,通常不用于自身发送数据。 value属性用作按钮的标签。

如果您想查看是否有向控制器发送请求的请求,可以使用类似以下的内容:

© www.soinside.com 2019 - 2024. All rights reserved.