Documentation

GetMultiSelectValue

array
CForm::GetMultiSelectValue(
 string question_sid,
 array answer_list,
 mixed form_values = false
)

If the array, passed in the parameter form_values, is initialized (for example, when editing the [link= 6660053#result]result[/link]), the method returns array of IDs for [link= 6660053#answer]answers[/link], selected among the group of "multiselect" type answers to a question, which symbolic identifier is specified in the parameter question_sid.

If the array, passed in the parameter form_values, is not initialized (for example, when creating new [link= 6660053#result]result[/link]), the method returns array of IDs for [link= 6660053#answer]answers[/link], selected by default. Search for the default answer is performed among the group of answers, specified in the parameter answer_list, by searching the line "checked" in the answer_list["param"][i]; if such line is found, the method sends this ID of [link= 6660053#answer]answer[/link] (stored in answer_list["reference_id"][i]) to the resulting array.

Non-static method.

Method parameters

Parameter Description
question_sid Symbolic identifier of [link= 6660053#question]question[/link].
answer_list Array of "multiselect" type answers to a question with question_sid. Minimally-required structure of this array:
Array
(
    [reference_id] => Array
        (
            [0] => ID of answer 1
            [1] => ID of answer 2
            [2] => ID of answer 3
            ...
        )

    [param] => Array
        (
            [0] => answer parameter 1
            [1] => answer parameter 2
            [2] => answer parameter 3
            ...
        )
)
form_values Associative array of values, received from the web form when creating new or editing existing [link= 6660053#result]result[/link] (standard array $_REQUEST). This array can be received via the function CFormResult::GetDataByIDForHTML.

Optional parameter. False by default.

See Also

Examples of use

<?
/*******************************************
       Result edit
*******************************************/

$RESULT_ID = 12; // Result ID

// if the "Save" is clicked...
if (strlen($_REQUEST["save"])>0)
{
  // use data, received from the web form  
  $arrVALUES = $_REQUEST; 
}
else
{
  // generate the array from the result data 
  $arrVALUES = CFormResult::GetDataByIDForHTML($RESULT_ID); 
}
?>
<form action="" method="POST">
<table>
  <tr>
    <td>Your education:</td>
    <td><?

      // question ID
      $QUESTION_SID = "EDUCATION"; 

      // array describing multiple selection list items
      $arMultiSelect = array (

        "reference" => array (
            "primary",
            "secondary professional",
            "higher",
          ),

        "reference_id" => array (
            602,
            603,
            604,
          ),

        "param" => array (
            "",
            "",
            "checked", // default value
          )
      );

      // get current value of on list 
      $arValues = CForm::GetMultiSelectValue($QUESTION_SID, $arMultiSelect, $arrVALUES);

      // display multiple selection list
      echo CForm::GetMultiSelectField(
        $QUESTION_SID,           // question symbolic identifier
        $arMultiSelect,          // array describing list items 
        $arValues,               // selected list item values
        10,                      // list height
        "class=\"inputselect\""  // list style
        );      
      ?></td>
  </tr>
</table>
<input type="submit" name="save" value="Save">
</form>


© «Bitrix24», 2001-2024