Documentation

GetCheckBoxValue

int
CForm::GetCheckBoxValue(
 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 result), the method returns ID of answer (answer["ID"]), if it was selected among the group of "checkbox" type answers to a question, which ID 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 will return the default value for this answer (answer["ID"]), if it was specified as the default answer (default answers have the "checked" line in в answer["FIELD_PARAM"]).

Non-static method.

Method parameters

Parameter Description
question_sid Symbolic identifier of [link= 6660053#question]question[/link].
answer Array, describing parameters of [link= 6660053#answer]answer[/link], with required keys:
  • ID - [link= 6660053#answer]answer[/link] ID;
  • FIELD_PARAM - if this key value contains the word "checked", this answer ID will be returned by this method by default (i. e. when creating new result).
form_values Associative array of values, received from web form when crating new or editing an existing [link= 6660053#result]result[/link] (standard array $_REQUEST). This array can also be received via the method 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>What are your areas of interest?</td>
        <td><?
            
            /**********************************************************
                display two checkboxes (math/physics) 
                as options to answer the question 
                "What are your areas of interest?"
            **********************************************************/

            $QUESTION_SID = "INTEREST"; // question 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 "physics"
            ***********************/

            // 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 "physics";
            ?></td>
    </tr>
</table>
<input type="submit" name="save" value="Save">
</form>


© «Bitrix24», 2001-2024