Documentation

SetField

CFormResult::SetField(
 int result_id,
 string field_sid,
 mixed value = false
)

The function updates the values of the answer to the question for the specified result or updates the value of the field. Non-static method.

Method parameters

Parameter Description Available from version
result_id ID of the result.
field_varname Deleted from version 4.0.4
field_sid Symbol ID of the question or field. 4.0.4
value Value to be saved. Depending on the type of the updated field, this parameter has different format.
  • When updating the value of the field, it is sufficient to specify a new value of the updated field in this parameter.
  • When updating the values of answers to question, this parameter has the following format:
    array (
    		answer ID 1 => answer value 1,
    		 answer ID 2 => answer value 2,
        ...
    )
    If the answer belongs to one of the following types:
    • radio - radio button;
    • checkbox - multiple selection checkbox;
    • dropdown - dropdown list element;
    • multiselect - multiselection list element,
    then the "answer value" must br "" (empty).

    If the answer has one of the following types:
    • text - single line text field;
    • textarea - multiline text field;
    • date - date input field;
    • password - password input field,
    as the "answer value" specify the value that can be typed when answering to this question.

    If the answer has one of the following types:
    • image - photo upload field;
    • file - random file upload field.
    then as the в "answer value" specify an array, describing the file and having the following keys:
    • name - file name;
    • size - file size;
    • tmp_name - temporary server path;
    • type - type of uploaded file.
    Such array can be retrieved via the function CFile::MakeFileArray.
Parameter value is optional. Starting from version 4.0.4 the default value is false (value of the field or value of the answer to question will be simply).

See Also

Examples of use


$RESULT_ID = 186;

/**************************************************************
            Updating answers to questions values  
**************************************************************/

// update answer to the question "Full name"
$arVALUE = array();
$FIELD_SID = "VS_NAME"; // question symbol identifier 
$ANSWER_ID = 586; // answer field ID 
$arVALUE[$ANSWER_ID] = "John Smith";
CFormResult::SetField($RESULT_ID, $FIELD_SID, $arVALUE);

// update answer to the question "Birthday"
$arVALUE = array();
$FIELD_SID = "VS_BIRTHDAY"; // question symbol identifier  
$ANSWER_ID = 587; // answer field ID 
$arVALUE[$ANSWER_ID] = "18.06.1975";
CFormResult::SetField($RESULT_ID, $FIELD_SID, $arVALUE);

// update answer to the question "Which areas of expertise you are interested in?"
$arVALUE = array();
$FIELD_SID = "VS_INTEREST"; // question symbol identifier 
$arVALUE[612] = ""; // "mathematics" answer field ID  
$arVALUE[613] = ""; // "physics" answer field ID  
$arVALUE[614] = ""; // "history" answer field ID 
CFormResult::SetField($RESULT_ID, $FIELD_SID, $arVALUE);

// update answer to the question "Photography"
$arVALUE = array();
$FIELD_SID = "VS_PHOTO"; // question symbol identifier 
$ANSWER_ID = 607; // answer field ID 
$path = $_SERVER["DOCUMENT_ROOT"]."/images/news.gif"; // path to file
$arVALUE[$ANSWER_ID] = CFile::MakeFileArray($path);
CFormResult::SetField($RESULT_ID, $FIELD_SID, $arVALUE);

// update answer to the question "CV"
$arVALUE = array();
$FIELD_SID = "VS_RESUME"; // question symbol identifier 
$ANSWER_ID = 610; // answer field ID 
$path = $_SERVER["DOCUMENT_ROOT"]."/docs/alawarauthorarea.doc"; // path to file
$arVALUE[$ANSWER_ID] = CFile::MakeFileArray($path);
CFormResult::SetField($RESULT_ID, $FIELD_SID, $arVALUE);

/**************************************************************
                Update the field values
**************************************************************/

// update value of the field "Quote"
$FIELD_SID = "VS_PRICE"; // question ID
$VALUE = "155";
CFormResult::SetField($RESULT_ID, $FIELD_SID, $VALUE);
?>


© «Bitrix24», 2001-2024