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] (
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:
|
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