Documentation

GetRadioValue

int
CForm::GetRadioValue(
 string question_sid,
 array answer,
 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 ID of the [link= 6660053#answer]answer[/link], selected among "radio"-type group of answers. The parameter question_sid contains the required identifier.

If the array, passed in the parameter form_values, is not initialized (for example, when creating new [link= 6660053#result]result[/link]), the method will return ID of the [link=902 6660053 4#answer]answer[/link] (answer["ID"]). If this answer was not set as the default answer (default answers have the "checked" line in the answer["FIELD_PARAM"]).

Non-staitc method.

Method parameters

Parameter Description
question_sid Symbolic identifier of the [link= 6660053#question]question[/link].
answer Array, describing the parameters of the [link= 6660053#answer]answer[/link], with the required keys:
  • ID - ID of the [link= 6660053#answer]answer[/link];
  • FIELD_PARAM - if the value of this key contains the "checked" word, the ID of this answer will be returned by this method by default (i. e. when creating a new [link= 6660053#result]result[/link]).
form_values Associative array of values, received from the web form when creating a new or editing an existing [link=90284#result]result[/link] (standard array $_REQUEST). This array can be also received by the method [link= 506542]CFormResult::GetDataByIDForHTML[/link].

Optional parameter. False by default.

See Also

Example 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>Do you smoke?</td>
        <td><?
            
            /**********************************************************
                display two radio buttons (yes/no) 
                as answer options to the question "Do you smoke?"
            **********************************************************/

            $QUESTION_SID = "SMOKE"; // question symbolic ID

            /***********************
                radio button "yes"
            ***********************/

            // array describing one of radio-buttons
            $arAnswer = array(
                "ID"            => 589,    // radio button ID
                "FIELD_PARAM"   => "checked class=\"inputradio\""   // answer parameter
                );
            
            // get current value
            $value = CForm::GetRadioValue($QUESTION_SID, $arAnswer, $arrVALUES);

            // display radio button
            echo CForm::GetRadioField(
                $QUESTION_SID,
                $arAnswer["ID"],
                $value,
                $arAnswer["FIELD_PARAM"]
                );            
            echo "yes <br>";

            /***********************
                radio button "no"
            ***********************/

            // array describing one of radio buttons
            $arAnswer = array(
                "ID"            => 590,    // radio button ID
                "FIELD_PARAM"   => ""      // answer parameter
                );
            
            // get current value
            $value = CForm::GetRadioValue($QUESTION_SID, $arAnswer, $arrVALUES);

            // display radio button
            echo CForm::GetRadioField(
                $QUESTION_SID,
                $arAnswer["ID"],
                $value,
                $arAnswer["FIELD_PARAM"]
                );            
            echo "no";
            ?></td>
    </tr>
</table>
<input type="submit" name="save" value="Save">
</form>


© «Bitrix24», 2001-2024
Up