Bitrix Site Manager

CFormResult::GetByID

record set
CFormResult::GetByID(
 int ID
);

The function returns a selection from the database containing the result fields and some parameters of a form.

Parameters

ParameterDescription
ID Result ID.

Return Values

Returns a database record containing the form parameters. See Example for details on handling the result.

Example

The following is an example of one row of the selection returned by CFormResult::GetByID.


Array
(
    [ID] => 176 (result ID)
    [TIMESTAMP_X] => 22.09.2003 17:11:04 (result modification date)
    [DATE_CREATE] => 22.09.2003 17:11:04 (result creation date)
    [STATUS_ID] => 4 (ID of the result status)
    [FORM_ID] => 4 (ID of the form)
    [USER_ID] => 2 (ID of the user who created the result)
    [USER_AUTH] => Y (user authorized)
    [STAT_GUEST_ID] => 32904 (user ID in the statistics module)
    [STAT_SESSION_ID] => 40348 (session ID in the statistics module)
    [NAME] => Visitor review (form name)
    [VARNAME] => ANKETA (form identifier)
    [IMAGE_ID] => 717 (ID of the form image)
    [DESCRIPTION] => This form is for test only (description)
    [DESCRIPTION_TYPE] => text (description type)
    [SHOW_RESULT_TEMPLATE] => default.php (form view template)
    [PRINT_RESULT_TEMPLATE] => default.php (form print template)
)

The below example shows the sample file "form_edit.php" allowing to edit the result.


<?
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/include.php");
include(GetLangFileName($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/form/admin/lang/", 
                        "/form_result_edit.php"));
$RESULT_ID = intval($RESULT_ID);
$z = CFormResult::GetByID($RESULT_ID);
if (!($arrResult=$z->Fetch())) 
{
    require_once ($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_after.php");
    echo ShowError("Survey form not found");
    require_once ($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog.php");
    die();
}
$WEB_FORM_ID = intval($arrResult["FORM_ID"]);
$F_RIGHT = intval(CForm::GetPermission($WEB_FORM_ID));

/*
Y - allow to edit the form fields
N - do not allow to edit the form fields
*/
$EDIT_ADDITIONAL = "N";

if ($F_RIGHT>=25 || ($F_RIGHT>=15 && $USER->GetID()==$arrResult["USER_ID"])) :

    // "Save results" clicked
    if ($REQUEST_METHOD=="POST" && 
             intval($WEB_FORM_ID)>0 && 
             (strlen($web_form_submit)>0 || strlen($apply)>0))
    {
        // obtain the form data array
        $arrVALUES = $HTTP_POST_VARS; 
        $error = CForm::Check($WEB_FORM_ID, $arrVALUES, $RESULT_ID);
        if (strlen($error)<=0) 
        {
            CFormResult::Update($RESULT_ID, $arrVALUES, $EDIT_ADDITIONAL);
            $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);
            if (strlen($web_form_submit)>0)
                LocalRedirect("index.php?WEB_FORM_NAME=".$arrResult["VARNAME"]);
        }
        else $strError .= $error;
    }
    else 
    // obtain the data array from the database
        $arrVALUES = CFormResult::GetDataByIDForWeb($RESULT_ID,$EDIT_ADDITIONAL); 
endif;

$title = str_replace("#RESULT_ID#","$RESULT_ID","Editing form # #RESULT_ID#");
$APPLICATION->SetTitle($title);
require_once ($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_after.php");
?>
<a href="index.php?web_form_name=<?=$arrresult["varname"]?>" class="navchain">Forms</a>
<br><br>
<table cellspacing="0" cellpadding="2">
    <?if ($F_RIGHT>=25):?>
    <tr>
        <td align="right" valign="top"><font class="tablebodytext"><b>ID:</b></font></td>
        <td valign="top"><font class="tablebodytext"><?=$arrResult["ID"]?></font></td>
    </tr>
    <tr>
        <td align="right" valign="top"><font class="tablebodytext"><b><?=GetMessage("FORM_FORM_NAME")?></b></font></td>
        <td valign="top"><font class="tablebodytext"><?
        echo "[<a class='tablebodylink' href='form_edit.php?lang=".lang."&id=".$web_form_id."'>". $WEB_FORM_ID."</a>] (".$arrResult["VARNAME"].") ".$arrResult["NAME"];
        ?></font></td>
    </tr>
    <?endif;?>
    <tr>
        <td align="right" valign="top"><font class="tablebodytext"><b><?=GetMessage("FORM_DATE_CREATE")?></b></font></td>
        <td valign="top"><font class="tablebodytext"><?=$arrResult["DATE_CREATE"]?></font></td>
    </tr>
    <tr>
        <td align="right" valign="top"><font class="tablebodytext"><b><?=GetMessage("FORM_TIMESTAMP")?></b></font></td>
        <td valign="top"><font class="tablebodytext"><?=$arrResult["TIMESTAMP_X"]?></font></td>
    </tr>
    <?if ($F_RIGHT>=25):?>
    <tr>
        <td align="right" valign="top"><font class="tablebodytext"><b><?=GetMessage("FORM_USER")?></b></font></td>
        <td valign="top" nowrap><font class="tablebodytext"><?
            if (intval($arrResult["USER_ID"])>0) :
                echo "<font class='tablebodytext'>[</font><a class='tablebodylink' title='".GetMessage("FORM_EDIT_USER")."' href='user_edit.php?lang=".lang."&id=".$arrresult["user_id"]."'>".$arrresult["user_id"]."</a><font class='tablebodytext'>] (".htmlspecialchars($arrResult["LOGIN"]).") ".htmlspecialchars($arrResult["USER_NAME"])."</font>";
                echo ($arrResult["USER_AUTH"]=="N") ? " <font class='filteroff'>".GetMessage("FORM_NOT_AUTH")."</font>" : "";
            else :
                echo "<font class='tablebodytext'>".GetMessage("FORM_NOT_REGISTERED")."</font>";
            endif;
            ?></font></td>
    </tr>
    <?if (CModule::IncludeModule("statistic")):?>
    <tr>
        <td align="right" valign="top"><font class="tablebodytext"><b><?=GetMessage("FORM_GUEST")?></b></font></td>
        <td valign="top"><font class="tablebodytext">[<a title="<?=GetMessage("FORM_GUEST_ALT")?>" class="tablebodylink" href="/bitrix/admin/guest_list.php?lang=<?=lang?>&find_id=<?=$arrresult["stat_guest_id"]?>&set_filter=y"><?=$arrresult["stat_guest_id"]?></a>]</font></td>
    </tr>
    <tr>
        <td align="right" valign="top"><font class="tablebodytext"><b><?=GetMessage("FORM_SESSION")?></b></font></td>
        <td valign="top"><font class="tablebodytext">[<a title="<?=GetMessage("FORM_SESSION_ALT")?>" class="tablebodylink" href="/bitrix/admin/session_list.php?lang=<?=lang?>&find_id=<?=$arrresult["stat_session_id"]?>&set_filter=y"><?=$arrresult["stat_session_id"]?></a>]</font></td>
    </tr>
    <?endif;?>
    <?endif;?>
</table>
<br>
<?
CForm::EditResult($RESULT_ID, $arrVALUES, $EDIT_RESULT_TEMPLATE, $EDIT_ADDITIONAL); 
require_once ($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog.php"); 
?>