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:
* - 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:
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