Documentation

Add

mixed
CFormResult::Add(
 int form_id,
 array values = false,
 string check_rights = "Y",
 int user_id = false
)

The method creates a new web form result. Returns ID of the new result on success, otherwise returns false. Non-static method.

This method does not create a mail event, associated with web form. To create a mail event, use CFormResult::Mail.

Note: in case of inactive questions, the web form data is not saved in them and error descriptions are not displayed.

Method parameters

Parameter Description
form_id Web form ID.
values Array with values of answers. The array has the following structure:
array(
    "HTML name for answer field 1" => "answer value 1",
    "HTML name for answer field 2" => "answer value 2",
    ...
    "HTML name for answer field N" => "answer value N"
)
Rules for generation of "HTML names for answer fields" and "answer values" are described in the section "HTML names for web form fields".
Example:
Array
(
    [form_text_586] => John Smith  
    [form_date_587] => 10.03.1992
    [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
)
Optional parameter. False by default (standard array $_REQUEST will be taken).
check_rights Flag specifying the current user access permissions. The following values are possible:
  • Y - check access permissions;
  • N - do not check access permissions.
To create new result, you should have the access permission to [10]the web form form_id filling out.

Optional parameter. Default values is "Y" (access permissions must be checked).
user_id ID of the user, who will be recorded as the creator of this [link= 6660053#result]result[/link].

Optional parameter. False by default (current user ID will be taken).

See Also

Examples of use

<?
// Web form ID
$FORM_ID = 4;

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

// array of answer values
$arValues = array (
    "form_text_586"                 => "John Smith",    // "Full name"
    "form_date_587"                 => "01.06.1904",     // "Date of birth"
    "form_textarea_588"             => " New York",      // "Address"
    "form_radio_VS_MARRIED"         => 590,              // "Married/single?"
    "form_checkbox_VS_INTEREST"     => array(612, 613),  // "Interests"
    "form_dropdown_VS_AGE"          => 601,              // "Age"
    "form_multiselect_VS_EDUCATION" => array(602, 603),  // "Education"
    "form_text_606"                 => 300,              // "Income"
    "form_image_607"                => $arImage          // "Photo"
);

// create new result 
if ($RESULT_ID = CFormResult::Add($FORM_ID, $arValues))
{
    echo "The #".$RESULT_ID." successfully created";
}
else
{
    global $strError;
    echo $strError;
}
?>


© «Bitrix24», 2001-2024