Documentation

GetDropDownValue

int
CForm::GetDropDownValue(
 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 result), the method returns array of IDs for answers, selected among "dropdown" type group of 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 result), the method returns array of IDs for answers, 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 answer (stored in answer_list["reference_id"][i]) to the resulting array.

Non-static method.

Method parameters

Parameter Description
question_sid Symbolic identifier of question.
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 existingresult (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>*Age:</td>
        <td><?

            // question ID
            $QUESTION_SID = "AGE"; 

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

                "reference" => array (
                        "-",
                        "10-19",
                        "20-29",
                        "30-39",
                        "40-49",
                        "50-59",
                        "60 and older"
                    ),

                "reference_id" => array (
                        608,
                        596,
                        597,
                        598,
                        599,
                        600,
                        601
                    ),

                "param" => array (
                        "not_answer class=\"inputselect\"", // is not an answer
                        "",
                        "checked", // default value
                        "",
                        "",
                        "",
                        ""
                    )
            );

             // get current value of dropdown list 
            $value = CForm::GetDropDownValue($QUESTION_SID, $arDropDown, $arrVALUES);

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


© «Bitrix24», 2001-2024
Up