Documentation

GetMultiSelectField

string
CForm::GetMultiSelectField(
 string question_sid,
 array list,
 array values = array(),
 mixed height = "",
 string add_to_multiselect = "class=\"inputselect\""
)

Returns HTML code of multiple selection list, intended to select answers from "multiselect" type answer group to the question, which symbolic identifier is passed in the parameter question_sid.

This method can be used both in the new result creation form, and the existing result editing form. Non-static method.

Note
Name of resulting HTML field will be generated by the following mask:
form_multiselect_question_sid[]

Method parameters

Parameter Description Available from version
question_sid Symbolic identifier of question.
list Array of "multiselect" type answers to a question with question_sid. Minimally-required structure of this array:
Array
(
    [reference] => array
        (
            [0] => answer title 1
            [1] => answer title  2
            [2] => answer title  3
            ...
        )

    [reference_id] => array
        (
            [0] => answer ID 1
            [1] => answer ID 2
            [2] => answer ID 3
            ...
        )
)
The parameter ANSWER_TEXT of the answer is used as the answer title.
values If this parameter passes array with values that match answer IDs, these answers will be selected (highlighted) in the resulting list:
<option value="element value" selected>element title</option>

Optional parameter. Default value - array() (empty array).
height Height of resulting multiple selection list:
<select multiple size="height" ...>

Optional parameter. Default value - "class=\"inputselect\"".
add_to_multiselect Custom HTML to be added into the resulting HTML tag:
<select add_to_multiselect ...>

Optional parameter. Default value - "class=\"inputselect\"".

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 multiple selection 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