Documentation

GetDateField

string
CForm::GetDateField(
 int answer_id,
 string html_form_name,
 string value = "",
 mixed size = "",
 string add_to_text = "class=\"inputtext\""
)

The method returns HTML code of single line text field. This field is intended for input of the "date" type answer. The resulting HTML code will contain an icon, leading to a page with calendar.

This method can be used in both the result creation form, and the existing result editing form. Non-static method.

Note
Name of resulting HTML field for date input will be generated by the following mask:
form_date_answer_id

Method parameters

Parameter Description Available from version
answer_id ID of answer.
html_form_name Name of HTML form for creation of new result or editing an existing result.
<form name="html_form_name" ...>

Optional parameter. Default value - "form1".
value Resulting text field value:
<input type="text" value="value" ...>

Optional parameter. Empty by default.
size Width of resulting text field for date input:
<input type="text" size="size" ...>

Optional parameter. Empty by default.
add_to_text Custom HTML to be added into resulting HTML tag of date input text field:
<input type="text" add_to_text ...>

Optional parameter. Default value - "class=\"inputtext\"".

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 fields
            // contains minimally-required fields
            $arAnswer = array(
                "ID"            => 587,   // ID of field for answer to question "Date of birth?"
                "VALUE"         => "",    // parameter ANSWER_VALUE (default value)
                "FIELD_WIDTH"   => 10,    // field width
                "FIELD_PARAM"   => ""     // field parameters
                );
            
            // get the 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
Up