Documentation

GetDataByID

CForm::GetDataByID(
 int FORM_ID,
 array &arForm,
 array &arQuestions,
 array &arAnswers,
 array &arDropDown,
 array &arMultiSelect,
 char(1) additional="Y"
);

The function returns arrays describing the form.

Parameters

FORM_ID Form ID.
arForm Array containing the form parameters with keys:
  • ID - Form ID
  • TIMESTAMP_X - modification date
  • NAME - form name
  • VARNAME - form identifier
  • BUTTON - button title for use with default.php
  • C_SORT - sort order
  • LID - ID of the site in which the form is used
  • IMAGE_ID - ID of the image in description
  • DESCRIPTION - form description
  • DESCRIPTION_TYPE - form description type (text|html)
  • SHOW_TEMPLATE - default template for the form display
  • MAIL_EVENT_TYPE - mail event type
  • MAIL_TEMPLATE - ID of the mail template
  • SHOW_RESULT_TEMPLATE - result display template
  • PRINT_RESULT_TEMPLATE - result print template
  • EDIT_RESULT_TEMPLATE - result editing template
  • STAT_EVENT1 - identifier event1 for the Statistics module.
  • STAT_EVENT2 - identifier event2 for the Statistics module.
  • STAT_EVENT3 - auxiliary identifier event3 for the Statistics module.
  • C_FIELDS - number of fields
  • QUESTIONS - number of questions
Sample
Array
(
    [ID] => 4
    [TIMESTAMP_X] => 17.09.2003 12:43:46
    [NAME] => Visitor review
    [VARNAME] => FORM
    [BUTTON] => Save
    [C_SORT] => 300
    [LID] => ru
    [IMAGE_ID] => 717
    [DESCRIPTION] => Used to collect info on visitors.
    [DESCRIPTION_TYPE] => text
    [SHOW_TEMPLATE] => default.php
    [MAIL_EVENT_TYPE] => FORM_FILLING_FORM
    [MAIL_TEMPLATE] => 262
    [SHOW_RESULT_TEMPLATE] => default.php
    [PRINT_RESULT_TEMPLATE] => default.php
    [EDIT_RESULT_TEMPLATE] => default.php
    [STAT_EVENT1] => form
    [STAT_EVENT2] => form
    [STAT_EVENT3] => 
    [C_FIELDS] => 1
    [QUESTIONS] => 9
)
arQuestions Array with questions and fields of the form. Each key in the array is a question or field identifier. Each value is an array describing a single question or field. Such array have the following keys.
  • ID - ID of a question or field
  • FORM_ID - form ID
  • TIMESTAMP_X - modification date of a question or field
  • ACTIVE - active state flag [Y|N]
  • TITLE - text of a question or a field title
  • TITLE_TYPE - type of text
  • VARNAME - identifier of a question or field
  • C_SORT - sort weight
  • ADDITIONAL - Y for questions, N for fields
  • REQUIRED - flag indicating the field is required [Y|N]
  • IN_FILTER - flag indicating the field or question is listed in the filter of the results form [Y|N]
  • IN_RESULTS_TABLE - flag indicating the field or question is listed in the table of results [Y|N]
  • FIELD_TYPE - field type
  • IMAGE_ID - ID of the image in the question description
  • COMMENTS - auxiliary comment
Sample
Array
(
    [VS_NAME] => Array
        (
            [ID] => 140
            [FORM_ID] => 4
            [TIMESTAMP_X] => 28.08.2003 11:45:57
            [ACTIVE] => Y
            [TITLE] => First and last name
            [TITLE_TYPE] => html
            [VARNAME] => VS_NAME
            [C_SORT] => 100
            [ADDITIONAL] => N
            [REQUIRED] => Y
            [IN_FILTER] => Y
            [IN_RESULTS_TABLE] => Y
            [FIELD_TYPE] => 
            [IMAGE_ID] => 
            [COMMENTS] => 
        )

    [VS_BIRTHDAY] => Array
        (
            [ID] => 141
            [FORM_ID] => 4
            [TIMESTAMP_X] => 16.09.2003 17:27:16
            [ACTIVE] => Y
            [TITLE] => Date of birth
            [TITLE_TYPE] => text
            [VARNAME] => VS_BIRTHDAY
            [C_SORT] => 200
            [ADDITIONAL] => N
            [REQUIRED] => Y
            [IN_FILTER] => Y
            [IN_RESULTS_TABLE] => Y
            [FIELD_TYPE] => 
            [IMAGE_ID] => 
            [COMMENTS] => 
        )
...
)
arAnswers Array with answers to questions of the form. Each key in the array is a question identifier. Each value is an array describing answers for a single question . Such array have the following keys.
  • ID - ID of the answer field
  • FIELD_ID - ID of the question
  • TIMESTAMP_X - modification date
  • MESSAGE - text [ANSWER_TEXT]
  • C_SORT - sort weight
  • ACTIVE - active state flag [Y|N]
  • VALUE - the value [ANSWER_VALUE]
  • FIELD_TYPE - type of the field
  • FIELD_WIDTH - field width
  • FIELD_HEIGHT - field height
  • FIELD_PARAM - additional user prameter
Sample
Array
(
    [VS_NAME] => Array
        (
            [0] => Array
                (
                    [ID] => 586
                    [FIELD_ID] => 140
                    [TIMESTAMP_X] => 2003-08-28 11:45:57
                    [MESSAGE] =>  
                    [C_SORT] => 100
                    [ACTIVE] => Y
                    [VALUE] => 
                    [FIELD_TYPE] => text
                    [FIELD_WIDTH] => 50
                    [FIELD_HEIGHT] => 0
                    [FIELD_PARAM] => 
                )

        )

    [VS_MARRIED] => Array
        (
            [0] => Array
                (
                    [ID] => 589
                    [FIELD_ID] => 143
                    [TIMESTAMP_X] => 2003-08-28 14:51:29
                    [MESSAGE] => yes
                    [C_SORT] => 100
                    [ACTIVE] => Y
                    [VALUE] => 
                    [FIELD_TYPE] => radio
                    [FIELD_WIDTH] => 0
                    [FIELD_HEIGHT] => 0
                    [FIELD_PARAM] => 
                )

            [1] => Array
                (
                    [ID] => 590
                    [FIELD_ID] => 143
                    [TIMESTAMP_X] => 2003-08-28 14:51:29
                    [MESSAGE] => no
                    [C_SORT] => 200
                    [ACTIVE] => Y
                    [VALUE] => 
                    [FIELD_TYPE] => radio
                    [FIELD_WIDTH] => 0
                    [FIELD_HEIGHT] => 0
                    [FIELD_PARAM] => 
                )

        )
...
)
arDropDown Array containing the suggested answers for fields of the type dropdown.
Sample
Array
(
    [VS_AGE] => Array
        (
            [reference] => Array
                (
                    [0] => -
                    [1] => 10-19
                    [2] => 20-29
                    [3] => 30-39
                    [4] => 40-49
                    [5] => 50-59
                    [6] => over 60
                )

            [reference_id] => Array
                (
                    [0] => 608
                    [1] => 596
                    [2] => 597
                    [3] => 598
                    [4] => 599
                    [5] => 600
                    [6] => 601
                )

            [param] => Array
                (
                    [0] => NOT_ANSWER
                    [1] => 
                    [2] => SELECTED
                    [3] => 
                    [4] => 
                    [5] => 
                    [6] => 
                )

        )

)
arMultiSelect Array containing the suggested answers for fields of the type multiselect.
Пример
Array
(
    [VS_EDUCATION] => Array
        (
            [reference] => Array
                (
                    [0] => school
                    [1] => college
                    [2] => post-graduate course
                )

            [reference_id] => Array
                (
                    [0] => 602
                    [1] => 603
                    [2] => 604
                )

            [param] => Array
                (
                    [0] => 
                    [1] => SELECTED
                    [2] => 
                )

        )

)
additional If set to "Y", the method returns form fields as well as questions in the array arQuestions. If "N" (default), questions only are returned.

Example



<?

    /*
        Returns the HTML code of the form with respect to the user permissions
        WEB_FORM_VARNAME - form identifier
        VARS - array of values for the form fields
        SHOW_TEMPLATE - form template
        PREVIEW - set to "Y" to disable the button "Save"
    */

    function Show($WEB_FORM_VARNAME, $arrVALUES=false, $SHOW_TEMPLATE=false, $PREVIEW="N")
    {
        $err_mess = (CAllForm::err_mess())."<".br>Function: Show<".br>Line: ";
        global $DB, $MESS, $APPLICATION, $USER, $HTTP_POST_VARS, $HTTP_GET_VARS;
        $z = CForm::GetBySID($WEB_FORM_VARNAME);
        $zr = $z->Fetch();
        $WEB_FORM_ID = intval($zr["ID"]);
        $WEB_FORM_ID = CForm::GetDataByID($WEB_FORM_ID, $arForm, 
                                          $arQuestions, $arAnswers, 
                                          $arDropDown, $arMultiSelect);
        if (intval($WEB_FORM_ID)>0)
        {
            $F_RIGHT = CAllForm::GetPermission($WEB_FORM_ID);
            if (intval($F_RIGHT)>=10)
            {
                if ($SHOW_TEMPLATE!==false) $template = $SHOW_TEMPLATE;
                else
                {
                    if (strlen($arForm["SHOW_TEMPLATE"])<=0) $template = "default.php";
                    else $template = $arForm["SHOW_TEMPLATE"];
                }
                require_once ($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/include.php");
                $path = COption::GetOptionString("form","SHOW_TEMPLATE_PATH");
                include (GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/lang/", "/include.php"));
                include(GetLangFileName($_SERVER["DOCUMENT_ROOT"].$path."lang/", "/".$template));
                include($_SERVER["DOCUMENT_ROOT"].$path.$template);
            }
        }
    }
?>
© «Bitrix24», 2001-2024
Up