Bitrix Site Manager

CFormResult::SetField

CFormResult::SetField(
 int RESULT_ID,
 varchar(255) FIELD_VARNAME,
 mixed VALUE
);

The method sets a new value of the form field result.

Parameters

ParameterDescription
RESULT_ID Result ID.
FIELD_VARNAME Form field symbolic identifier.
VALUE New value to be set.

Example

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");
?>