Documentation

GetRadioField

string
CForm::GetRadioField(
 string question_sid,
 int answer_id,
 mixed value = "",
 string add_to_radio = "class=\"inputradio\""
)

The method returns HTML code for radio button, intended for "radio" type selection of [link=90284#answer]answer[/link]. The answer ID is passed in the parameter question_sid.

This method can be used for both the new created [link=90284#result]result[/link] and the editing of existing result. Non-static method.

Name of resulting HTML field will be generated by the following mask: form_radio_question_sid

Method parameters

Parameter Description
question_sid ID of [link=90284#question]question[/link].
answer_id ID [link=90284#answer]answer[/link].
value If this parameter passes the value that matches with answer_id, the radio button will be selected (checked):
<input type="radio" checked ...>
Optional parameter. Empty by default.
add_to_radio Custom HTML to be added to the resulting radio button HTML tag:
<input type="radio" add_to_radio ...>
If "checked" keyword is specified in this parameter, this Radio button will be selected by default.
Optional parameter. "class=\"inputradio\"" by default.

See Also

  • [link=90311]CForm::GetRadioValue[/link]
  • [link=90281]HTML field names[/link]

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

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

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

            // array describing one of radio buttons 
            // contains minimally-requried fields
            $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 
            // contains minimally-requried fields
            $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