Documentation

Update

bool
CFormResult::Update(
 int result_id,
 array values = false,
 string update_fields = "N",
 string check_rights = "Y"
)

Updates all values of answers and fields for the result of web form. Returns true on success, false otherwise. Non-static method.

Method parameters

Parameter Description
result_id Result ID.
values Array with values of answers and fields of web form. Array has the following structure:
array(
    "HTML name of field 1" => "value 1",
    "HTML name of field 2" => "value 2",
    ...
    "HTML name of field N" => "value N"
)
Rules for generating "HTML field names" and "values" can be viewed here.
Example:
Array
(
    [form_text_586] => John Smith
    [form_date_587] => 10.03.1984
    [form_textarea_588] => New York
    [form_radio_VS_MARRIED] => 589
    [form_checkbox_VS_INTEREST] => Array
        (
            [0] => 592
            [1] => 593
            [2] => 594
        )

    [form_dropdown_VS_AGE] => 597
    [form_multiselect_VS_EDUCATION] => Array
        (
            [0] => 603
            [1] => 604
        )

    [form_text_606] => 2345
    [form_image_607] => 1045
    [form_textarea_ADDITIONAL_149] => 155
)
Optional parameter. False by default (standard array $_REQUEST will be taken).
update_fiels Flag that defines the requirement to update fields of the web form. Possible values:
  • Y - must be updated;
  • N - no updates necessary.
Optional parameter. Set to "N" by default (no updates needed).
check_rights Flag that defines the requirement to check current user access permissions. The following values are required:
  • Y - access permissions must be checked;
  • N - access permissions must not be checked.
To successfully update the result, the following access permissions are required:
  1. For the web form with the edited result:

    [20] Handling of all results according to their statuses

    or in case, if you are the creator of the edited result - the following access permission is required:

    [15] Handling of its own result according to its status
  2. For the status that contains the edited result, the following access permission is required:

    [EDIT] editing
Optional parameter. Set to "Y" by default (access permissions must be checked).

See Also

Examples of use

<?
// Result ID
$RESULT_ID = 186;

// array describing the photo, uploaded onto the server
$arImage = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/photo.gif");

// array of answer and field values for the web form 
$arValues = array (
    "form_text_586"                 => "John Smith",    // "Full name"
    "form_date_587"                 => "01.06.1984",     // "Date of birth"
    "form_textarea_588"             => "New York",      // "Address"
    "form_radio_VS_MARRIED"         => 590,              // "Marital status?"
    "form_checkbox_VS_INTEREST"     => array(612, 613),  // "Hobbies"
    "form_dropdown_VS_AGE"          => 601,              // "Age"
    "form_multiselect_VS_EDUCATION" => array(602, 603),  // "Education"
    "form_text_606"                 => 300,              // "Income"
    "form_image_607"                => $arImage,         // "Photo"
    "form_textarea_ADDITIONAL_149"  => "155 USD"      // "Estimated sum"
)

//update the result
if (CFormResult::Update($RESULT_ID, $arValues, "Y"))
{
    echo "The #".$RESULT_ID." updated successfully.";
}
else
{
    global $strError;
    echo $strError;
}
?>


© «Bitrix24», 2001-2024
Up