Bitrix Site Manager

CFormResult::GetDataByID

array
CFormResult::GetDataByID(
 int RESULT_ID,
 array arrFIELD_VARNAME,
 array &arrRES,
 array &arrANSWER
);

The function returns answers to the form questions and form fields values from the result stored in the database.

Parameters

ParameterDescription
RESULT_ID Result ID.
arrFIELD_VARNAME Array of ID's of the form questions and fields for which the values are to be returned.
arrRES Array containing the form result fields on return (see Example).
arrANSWER Array containing answers to the form questions and the fields values on return (see Example).

Example

Sample array arrRES


Array
(
    [ID] => 146
    [TIMESTAMP_X] => 2003-09-18 01:20:15
    [DATE_CREATE] => 18.09.2003 01:20:15
    [VALID] => Y
    [FORM_ID] => 4
    [USER_ID] => 1
    [USER_AUTH] => Y
    [STAT_GUEST_ID] => 33
    [STAT_SESSION_ID] => 171
)

Sample array arrANSWER


arrANSWERArray
(
    [VS_NAME] => Array
        (
            [586] => Array
                (
                    [RESULT_ID] => 147
                    [FIELD_ID] => 140
                    [ANSWER_ID] => 586
                    [ANSWER_TEXT] => 
                    [ANSWER_VALUE] => 
                    [USER_TEXT] => John
                    [USER_FILE_ID] => 
                    [USER_FILE_NAME] => 
                    [USER_DATE] => 
                    [VARNAME] => VS_NAME
                    [TITLE] => name
                    [TITLE_TYPE] => html
                    [MESSAGE] =>  
                    [VALUE] => 
                    [FIELD_TYPE] => text
                    [FIELD_WIDTH] => 50
                    [FIELD_HEIGHT] => 0
                    [FIELD_PARAM] => 
                )

        )

    [VS_PHOTO] => Array
        (
            [607] => Array
                (
                    [RESULT_ID] => 147
                    [FIELD_ID] => 148
                    [ANSWER_ID] => 607
                    [ANSWER_TEXT] => 
                    [ANSWER_VALUE] => 
                    [USER_TEXT] => 
                    [USER_FILE_ID] => 704
                    [USER_FILE_NAME] => apc.jpg
                    [USER_DATE] => 
                    [VARNAME] => VS_PHOTO
                    [TITLE] => photo
                    [TITLE_TYPE] => text
                    [MESSAGE] =>  
                    [VALUE] => 
                    [FIELD_TYPE] => image
                    [FIELD_WIDTH] => 30
                    [FIELD_HEIGHT] => 0
                    [FIELD_PARAM] => 
                )

        )

)

Sample array returned by GetDataByID


Array
(
    [VS_NAME] => Array
        (
            [0] => Array
                (
                    [RESULT_ID] => 147
                    [FIELD_ID] => 140
                    [ANSWER_ID] => 586
                    [ANSWER_TEXT] => 
                    [ANSWER_VALUE] => 
                    [USER_TEXT] => John
                    [USER_FILE_ID] => 
                    [USER_FILE_NAME] => 
                    [USER_DATE] => 
                    [VARNAME] => VS_NAME
                    [TITLE] => name
                    [TITLE_TYPE] => html
                    [MESSAGE] =>  
                    [VALUE] => 
                    [FIELD_TYPE] => text
                    [FIELD_WIDTH] => 50
                    [FIELD_HEIGHT] => 0
                    [FIELD_PARAM] => 
                )

        )

    [VS_PHOTO] => Array
        (
            [0] => Array
                (
                    [RESULT_ID] => 147
                    [FIELD_ID] => 148
                    [ANSWER_ID] => 607
                    [ANSWER_TEXT] => 
                    [ANSWER_VALUE] => 
                    [USER_TEXT] => 
                    [USER_FILE_ID] => 704
                    [USER_FILE_NAME] => apc.jpg
                    [USER_DATE] => 
                    [VARNAME] => VS_PHOTO
                    [TITLE] => Photo
                    [TITLE_TYPE] => text
                    [MESSAGE] =>  
                    [VALUE] => 
                    [FIELD_TYPE] => image
                    [FIELD_WIDTH] => 30
                    [FIELD_HEIGHT] => 0
                    [FIELD_PARAM] => 
                )

        )

)

The below example shows the sample file "form_fill.php" displaying the form.


<?
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
if (CModule::IncludeModule("form"))
{
    if (intval($WEB_FORM_ID)>0) 
        $z = <b>CForm::GetByID</b>($WEB_FORM_ID); 
    else 
        $z = CForm::GetBySID($WEB_FORM_NAME);

    if (!($zr=$z->Fetch())) 
    {
        $FORM_EXIST = "N";
        $strError .= "Invalid form ID.<br>";
    }
    else
    {
        $FORM_EXIST = "Y";
        $WEB_FORM_ID = $zr["ID"];
        $WEB_FORM_NAME = $zr["VARNAME"];
        if ($REQUEST_METHOD=="POST" && 
            intval($WEB_FORM_ID)>0 && 
            strlen($web_form_submit)>0)
        {
            $arrVALUES = $HTTP_POST_VARS;
            $error = CForm::Check($WEB_FORM_ID);
            if (strlen($error)<=0)
            {
                if ($RESULT_ID = CFormResult::Add($WEB_FORM_ID))
                {
                    $arr = CFormResult::GetDataByID($RESULT_ID, array("VS_PHOTO"));
                    $PHOTO_EXIST = (intval($arr["VS_PHOTO"][0]["USER_FILE_ID"])>0) ? "Y" : "N";
                    CFormResult::SetField($RESULT_ID, "VS_PHOTO_EXIST", $PHOTO_EXIST);
                    CForm::SetEvent($RESULT_ID);
                    CForm::Mail($RESULT_ID);
                    LocalRedirect("index.php?WEB_FORM_NAME=".$WEB_FORM_NAME. "&strNote=".urlencode("Information saved"));
                }
            }
            else 
                $strError .= $error;
        }
    }
}

if (strlen($APPLICATION->GetTitle()) <= 0)
    $APPLICATION->SetTitle("Visitor survey");

require_once ($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_after.php");
echo ShowNote($strNote);
echo ShowError($strError);
?><?
if (CModule::IncludeModule("form"))
    CForm::Show($WEB_FORM_NAME, $arrVALUES); 
require_once ($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog.php");
?>