将Multiselect字段插入数组字段

时间:2016-05-25 12:52:24

标签: php arrays json

我想在多选字段(从HTML表单)中插入所选选项到数组中,稍后将其传递到 JIRA API

以下是多选字段,我用数据库中的值填充:

<div class="s-10 1-8">
    <select id="insightList" multiple="multiple" name="arisUserGroup[]">
        <optgroup label="User Group">
            <?php
            $result = DB::getInstance()->get('vwcustomfieldsoptions',array('id','=',14923));
            foreach($result->results() as $result)
            { ?>
                <option value="<?php echo $result->custid ?>"><?php echo $result->customvalue ?></option>
            <?php } ?>
        </optgroup>
    </select>
</div>

以下是我用于使用HTML表单中的值创建新数组的方法:

public function userPersmissions($summary, $dbName, $userId, $arisUserGroup, $arisFolderPath)
{
    $json = Array ( "fields" => Array (
        "project" => Array
        ( "id" => 19806 ),
        "summary" => $summary,
        "issuetype" => Array ( "name" => "User Permissions" ),

        "customfield_14922" =>Array (
            "id" => $dbName
        ),
        "customfield_14447" =>$userId,

        "customfield_14923" =>Array (
            "id" => $arisUserGroup
        ),

        "customfield_15579" =>$arisFolderPath

    )
    );

    return $json;
}

然后我将上面的关联数组转换为json数组,并使用以下方法将其传递给JIRA rest API:

public function processArray($json)
{
    $url_send ="http://jira.food.co.za:8091/rest/api/2/issue/";
    $str_data = json_encode($json);

    $data=json_encode($str_data);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url_send);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl,CURLOPT_HTTPHEADER,array('Accept: application/json; charset=UTF-8','Content-Type: application/json','Content-Length: ' . strlen($str_data),'X-Stream: true'));
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($curl, CURLOPT_POSTFIELDS,$str_data);
    $result1 = curl_exec($curl);
    curl_close($curl);
    return $result1;
}

但是我收到以下错误:

  

{&#34; errorMessages&#34;:[],&#34;错误&#34;:{&#34; ARIS用户组&#34;:&#34;数据不是   阵列&#34;}}

json中多重选择字段的格式为:

"customfield_10008": [ {"value": "red" }, {"value": "blue" }, {"value": "green" }]

我尝试使用的json链接是:https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-create-issue

当我在multiselect上执行var_dump时,我得到一个空字符串。意味着问题从那里开始。

0 个答案:

没有答案