Documentation

GetCheckBoxField

string
CForm::GetCheckBoxField(
 string question_sid,
 int answer_id,
 mixed value = "",
 string add_to_checkbox = "class=\"inputcheckbox\""
)

The method returns HTML code for multiple selection flag (checkbox), intended for selection of "checkbox" type answer to a question, which symbolic identifier is passed in the parameter question_sid. Non-static method.

This method can be used both in form of creating new result, and in the form of editing an existing result.

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

Method parameters

Parameter Description
question_sid Symbolic identifier of question.
answer_id ID of answer.
value If this parameter passes value that match with answer_id, the multiple selection flag will be checked:
<input type="checkbox" checked ...>

Optional parameter. Empty by default.
add_to_checkbox Custom HTML to be added into the resulting HTML tag of multiple selection flag:
<input type="checkbox" add_to_checkbox ...>

It must be considered, that if the "checked" keyword is specified in this parameter, this selector will be selected by default.

Optional parameter. By default - "class=\"inputcheckbox\"".

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>What areas of knowledge you are interested in?</td>
        <td><?
            
            /**********************************************************
                display two checkboxes (math/physics) 
                as two options to answer the question 
                "What areas of knowledge you are interested in?"
            **********************************************************/

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

            /***********************
              checkbox "math"
            ***********************/

            // array describing one checkbox
            // contains minimally-required fields
            $arAnswer = array(
                "ID"            => 591,            // checkbox ID
                "FIELD_PARAM"   => "checked class=\"inputcheckbox\""   // answer parameter
                );

            // get current value
            $value = CForm::GetCheckBoxValue($QUESTION_SID, $arAnswer, $arrVALUES);

            // display the checkbox
            echo CForm::GetCheckBoxField(
                $QUESTION_SID,
                $arAnswer["ID"],
                $value,
                $arAnswer["FIELD_PARAM"]
                );            
            echo "math<br>";

            /***********************
                checkbox "физика"
            ***********************/

            // array describing one checkbox
            // contains minimally-required fields
            $arAnswer = array(
                "ID"            => 593,       // checkbox ID 
                "FIELD_PARAM"   => ""         // answer parameter
                );

            // get current value
            $value = CForm::GetCheckBoxValue($QUESTION_SID, $arAnswer, $arrVALUES);

            // display the checkbox
            echo CForm::GetCheckBoxField(
                $QUESTION_SID,
                $arAnswer["ID"],
                $value,
                $arAnswer["FIELD_PARAM"]
                );            
            echo "физика";
            ?></td>
    </tr>
</table>
<input type="submit" name="save" value="Save">
</form>


© «Bitrix24», 2001-2024