$ _REQUEST在表单提交数组值时给出空值

时间:2015-12-16 08:01:50

标签: php html5

这是我的网址

db_control.php?workname=Test+message&worktype=1&workscore=10&multi%5B%5D=4&multi%5B%5D=24&frmsubmit=

这是我的PHP代码

if(isset($_REQUEST['frmsubmit']))
{
    echo $_REQUEST['workname']; echo '<br>';
    echo $_REQUEST['workscore'];echo '<br>';
    foreach($_REQUEST['multi'] as $mlti => $n)
    {
        echo $n;echo '<br>';
    }
}

我收到了这个答案

测试消息 10

$_REQUEST['multi'] returns empty why..?

这些都来自表格帖子(表格方法是获得)

我做错了什么?请以正确的方式引导我。提前谢谢。

这是我的HTML代码

<form enctype="multipart/form-data" class="form-horizontal ng-pristine ng-valid" id="work_assignment" method="get" action="<?=BASE_URL?>db_control.php" role="form">
    <div class="box-body">
        <label class="col-sm-3 control-label" for="name">Work Name<font class="redFont">*</font></label>
        <div class="controls col-sm-6">
            <input class="form-control" id="workname" required="required" name="workname" value="" type="text">
        </div>

    </div>
            <div class="box-body">
    <div class="row" id="field_name">
        <label class="col-sm-3 control-label" for="name">Work Type<font class="redFont">*</font></label>
        <div class="controls col-sm-6">
            <select class="select2-container form-control select2Field" id="worktype" name="worktype" onchange="hidescore(this)">
                                <option value="1">KRA</option>
                                <option value="2">Regular Task</option>
                                <option value="3">SELF Task</option>
                            </select>
        </div>                  
    </div>
            <div class="box-body">              
    <div class="row" id="field_namews">
        <label id="hidsco" class="col-sm-3 control-label" for="name">Work Score</label>
            <div class="controls col-sm-6">
            <input class="form-control" id="workscore" name="workscore" value="" type="text">
            </div>

    </div>

    <div class="row" id="field_name">
        <label class="col-sm-3 control-label" for="name">Employee<font class="redFont">*</font></label>
        <div class="controls col-sm-6" style="height:130px">
                            <select name="multi[]" multiple="multiple" style="height:100%"><!--onchange="setmail(this)"-->
                <option value="1">SudarshanSeshadri (1000)</option>
                <option value="3">Sonal Nahata (1010)</option>
                <option value="4">SujishV (1002)</option>
                <option value="33">JohnbabuAmose (0001)</option>
                <option value="34">GeethaVijay (1086)</option>
                <option value="35">BabuAmose (2100000)</option>
                <option value="36">SudhakarJeevan (102)</option>                                                                    </select>
        </div>

    </div>

    <div class="control-group row">
            <div class="controls col-sm-9">
            <button type="submit" class="btn btn-primary pull-right" name="frmsubmit"><i class="fa fa-save"></i> Save</button>
            <button type="button" class="btn pull-right" style="margin-right:5px;" onclick="cancelsave()"><i class="fa fa-times-circle-o"></i> Cancel</button>
            </div>

    </div>

1 个答案:

答案 0 :(得分:-1)

执行此操作的正确方法是以下列方式将多个值放在一个参数multi中。

使用:

  

http://example.com/workname=Test+message&worktype=1&workscore=10&multi=4,24&frmsubmit=

而不是:

  

http://example.com/workname=Testmessage&worktype=1&workscore=10&multi[]=4&multi[]=24&frmsubmit=

使用explode像这样访问“multi”的值:

if(isset($_REQUEST['frmsubmit']))
{
    echo $_REQUEST['workname']; echo '<br>';
    echo $_REQUEST['workscore'];echo '<br>';
    $multiParam = explode(",",$_REQUEST['multi']);
    foreach($multiParam as $mlti => $n)
    {
        echo $n;echo '<br>';
    }
}

编辑:另请阅读@ EduardoFernandes的回答here以获取更多信息。