Documentation

Set

mixed
CFormField::Set(
 array fields,
 mixed field_id = false,
 string check_rights = "Y"
)

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

Parameters

Parameter Description
fields Array of values which accept the following keys:
  • SID* - the symbolic identifier of the question or the field;
  • FORM_ID* - the webform ID;
  • ACTIVE - active state flag. The following values are possible:
  • ADDITIONAL - the following values are possible:
    • Y - the record is the web form field;
    • N - the record is the web form question (by default).
  • FIELD_TYPE* - type of the field. The following values are possible:
    • text - text;
    • integer - number;
    • date - date.
  • TITLE - the text of the question or the field title;
  • TITLE_TYPE* - type of the question. The following values are possible:
    • text - text;
    • html - HTML code.
  • C_SORT - sort order;
  • REQUIRED* - specifies the question must be answered:
    • Y - answer to this question is mandatory;
    • N - answer to this question is mandatory (by default).
  • FILTER_TITLE - filter field title;
  • IN_RESULTS_TABLE - specifies the entity (question or field) should be included in the HTML table of results:
    • Y - included;
    • N - not included (by default).
  • IN_EXCEL_TABLE - specifies the entity (question or field) should be included in the Excel table of results:
    • Y - included;
    • N - not included (by default).
  • RESULTS_TABLE_TITLE - title of the result table column;
  • COMMENTS - administrative comments;
  • arIMAGE** - array containing the question image description. The following values are possible in this array:
    • name - file name;
    • size - file size;
    • tmp_name - temporary path on the server;
    • type - type of the uploaded file;
    • del - set to "Y" to delete the image;
    • MODULE_ID - the Web Form module identifier (form).
  • arANSWER** - array containing answers to the question. Has the following structure:
    Array
    (
        [0] => Array
            (
                [ID] => ID
                [DELETE] => specifies to delete this answer [Y|N]
                [MESSAGE] => ANSWER_TEXT parameter 
                [VALUE] => ANSWER_VALUE parameter
                [C_SORT] => sort order
                [ACTIVE] => active state flag [Y|N]
                [FIELD_TYPE] => 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] => input field width
                [FIELD_HEIGHT] => input field height
                [FIELD_PARAM] => additional parameters; 
                    any HTML tags are allowed here; 
                    types marked with asterisk allows the following reserved values:
    
                    checked - answer is selected (synonym: selected) (default);
                    not_answer - if this item is selected, 
                                 a user has not given an answer to the question.
                              Usually, the first item in a list. Important when
                              REQUIRED="Y")
            )
        [1] => array containing the following answer
        ...
    )
  • arFILTER_USER** - array of filter fields used to filter by the value of the answer entered by a user when filling in the web form. The following values are possible in this array:
  • arFILTER_ANSWER_TEXT** - array of filter fields used to filter by the value of the ANSWER_TEXT answer parameter. The following values are possible in this array:
  • arFILTER_ANSWER_VALUE** - array of filter fields used to filter by the value of the ANSWER_VALUE response parameter. The following values are possible in this array:
  • arFILTER_FIELD* - array of filter fields used to filter by the web form fields values:

* - required;
* - required by webform fields only;
** - required by webform questionsonly.
field_id The ID of the modified question or field.
Optional. False by default (adds a new question or a field).
check_rights Flag specifying the current user permissions should be checked. One of the following values is possible:
  • Y - permissions should be checked;
  • N - no checks need to be performed.
To add a new question or a field or to modify their parameters, you should have the permission [30] Full access for the destination web form specified in fields["FORM_ID"].

Optional. "Y" by default which means the permissions should be checked.

See Also

  • [link=506535CFormField fields[/link]
  • [link=6660064]Web form permissions[/link]
  • CFile::MakeFileArray

Example



<?
/*************************************************
         Add a web form question
*************************************************/

// create an array containing the description of image 
// stored in the file on server
$arIMAGE = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/question.gif");
$arIMAGE["MODULE_ID"] = "form";

// build an array of answers
$arANSWER = array();

$arANSWER[] = array(
    "MESSAGE"     => "yes",                           // ANSWER_TEXT parameter
    "C_SORT"      => 100,                            // sort order 
    "ACTIVE"      => "Y",                            // active state flag
    "FIELD_TYPE"  => "radio",                        // type of the answer
    "FIELD_PARAM" => "checked class=\"inputradio\""  // the answer parameters
    );

$arANSWER[] = array(
    "MESSAGE"     => "no",
    "C_SORT"      => 200
    "ACTIVE"      => "Y",
    "FIELD_TYPE"  => "radio"
    );

// build an array of fields
$arFields = array( 
    "FORM_ID"              => 4,                     // The web form ID
    "ACTIVE"               => Y,                     // active state flag
    "TITLE"                => "Are you married?",    // text of the question
    "TITLE_TYPE"           => "text",                // type of the question text
    "SID"                  => "VS_MARRIED",          // question symbolic identifier
    "C_SORT"               => 400,                   // sort order
    "ADDITIONAL"           => "N",                   // we need a web form question
    "REQUIRED"             => "Y",                   // the question must be answered
    "IN_RESULTS_TABLE"     => "Y",                   // add to HTML table of results
    "IN_EXCEL_TABLE"       => "Y",                   // add to Excel table of results
    "FILTER_TITLE"         => "Married",             // filter field title
    "RESULTS_TABLE_TITLE"  => "Married",             // table title
    "arIMAGE"              => $arIMAGE,              // question image
    "arFILTER_ANSWER_TEXT" => array("dropdown"),     // type of filter by ANSWER_TEXT
    "arANSWER"             => $arANSWER,             // array of answers
);

// add a new question
$NEW_ID = CFormField::Set($arFields);
if ($NEW_ID>0) echo "A new question with ID=".$NEW_ID has been added;
else // error
{
    // display the error description
    global $strError;
    echo $strError;
}
?>

<?
/*************************************************
          Add a web form field
*************************************************/

$arFields = array( 
    "FORM_ID"             => 4
    "ACTIVE"              => "Y",
    "TITLE"               => "Calculated price",
    "SID"                 => "VS_PRICE",
    "C_SORT"              => 1000,
    "ADDITIONAL"          => "Y",
    "IN_RESULTS_TABLE"    => "Y",
    "IN_EXCEL_TABLE"      => "Y",
    "FIELD_TYPE"          => "text",
    "FILTER_TITLE"        => "Price",
    "RESULTS_TABLE_TITLE" => "Price",
    "arFILTER_FIELD"      => array("text")
    );

// add a new field
$NEW_ID = CFormField::Set($arFields);
if ($NEW_ID>0) echo "A new field with ID=".$NEW_ID has been added;
else // error
{
    // display the error description
    global $strError;
    echo $strError;
}
?>
© «Bitrix24», 2001-2024