Documentation

GetDateValue

string
CForm::GetDateValue(
 int answer_id,
 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 current value of the "date" type [link= 6660053#answer]answer[/link], which ID is passed in the parameter answer_id.

If the array, passed in the parameter form_values, is not initialized (for example, when creating new [link= 6660053#result]result[/link]), the method returns default value for this answer (i. e. the value specified in the answer["VALUE"]).

Non-static method.

method parameters

Parameter Description
answer_id ID of answer.
answer Array, describing the parameters of [link= 6660053#answer]answer[/link], with required VALUE key and the value that contains the default value for [link= 6660053#answer]answer[/link]. Generally, such default value is the parameter ANSWER_VALUE of [link= 6660053#answer]answer[/link].
form_values Associative array of values, received from the web form when creating new or editing existing [link= 6660053#result]result[/link] (standard array $_REQUEST). This array can be received via the function 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 name="FORM" action="" method="POST">
<table>
    <tr>
        <td>Date of birth:</td>
        <td><?

            // array describing the date input field
            // contains minimally-require fields
            $arAnswer = array(
                "ID"            => 587,   // ID of the field for answer to question "Date of birth?"
                "VALUE"         => "",    // parameter ANSWER_VALUE (default value)
                "FIELD_WIDTH"   => 10,    // field width
                "FIELD_PARAM"   => ""     // field parameters
                );
            
            // get current value
            $value = CForm::GetDateValue($arAnswer["ID"], $arAnswer, $arrVALUES);

            // display the field
            echo CForm::GetDateField(
                $arAnswer["ID"],
                "FORM",
                $value,
                $arAnswer["FIELD_WIDTH"],
                $arAnswer["FIELD_PARAM"]
                );
            ?></td>
    </tr>
</table>
<input type="submit" name="save" value="Save">
</form>


© «Bitrix24», 2001-2024