Documentation

Set

mixed
CFormAnswer::Set(
 array fields,
 mixed answer_id = false,
 mixed current_question_id = false
)

The method Set adds a new answer or modifies the existing one. Returns the ID of the modified or added answer on success, or false otherwise.

Parameters

fields Array of value which accept the following keys:
  • QUESTION_ID* - the вопроса ID;
  • MESSAGE* - the value of the answer parameter ANSWER_TEXT;
  • VALUE - the value of the answer parameter ANSWER_VALUE;
  • C_SORT - sort order;
  • ACTIVE - active state flag. One of the following values is possible:
    • Y - the answer is active;
    • N - the answer is inactive (default).
  • FIELD_TYPE - answer field type. The following values are possible:
    • text - single line text input field;
    • textarea - multiline text input field;
    • radio - mutually exclusive button (radio button);
    • checkbox - multiple selection flags (checkbox);
    • dropdown - drop-down list;
    • multiselect - multiple selection list;
    • date - date input field;
    • image - image upload field;
    • file - file upload field;
    • password - password input field;
  • FIELD_WIDTH - answer field width;
  • FIELD_HEIGHT - answer field height;
  • FIELD_PARAM - answer field parameters.
* - required fields.
answer_id The ID of the modified answer.
Optional parameter. False by default which means a new answer is to be added.
current_question_id The ID of the answer to which the modified answer is bound. If specified, this parameter will speed up the method execution.
Optional parameter. False by default.

See Also

Example



<?
$QUESTION_ID = 140; // The ID of the question "First and last names"

$arFields = array(
    "QUESTION_ID"   => $QUESTION_ID,
    "MESSAGE"       => " ",
    "C_SORT"        => 100,
    "ACTIVE"        => "Y",
    "FIELD_TYPE"    => "text",
    "FIELD_WIDTH"   => "40"
    );

$NEW_ID = CFormAnswer::Set($arFields);
if ($NEW_ID>0)
    echo "The ID=".$NEW_ID." has been successfully added";
else // error
{
    // display the error description
    global $strError;
    echo $strError;
}
?>

<?
$QUESTION_ID = 143; // The ID of the question "Are you married?"

$arFields = array(
    "QUESTION_ID"      => $QUESTION_ID,
    "MESSAGE"       => "yes",
    "C_SORT"        => 100,
    "ACTIVE"        => "Y",
    "FIELD_TYPE"    => "radio",
    "FIELD_PARAM"   => "checked"
    );
CFormAnswer::Set($arFields);

$arFields = array(
    "QUESTION_ID"      => $QUESTION_ID,
    "MESSAGE"       => "no",
    "C_SORT"        => 200,
    "ACTIVE"        => "Y",
    "FIELD_TYPE"    => "radio"
    );
CFormAnswer::Set($arFields);
?>
© «Bitrix24», 2001-2024
Up