Set
mixed CForm::Set( array fields, mixed form_id = false, string check_rights = "Y" )
The method adds new [link= 6660053#form]Web form[/link] or updates the existing one. Returns ID of the updated or added web form on success, otherwise returns false. Non-static method.
Note
When updating an existing web form (or adding a new web form), the type of mail event is updated automatically (or a new type of mail event is created).
Method parameters
Parameter | Description |
---|---|
fields | Array of field values. The following array keys are possible:
|
form_id | ID of updated web form. Optional parameter. False by default (new web form is added). |
check_rights | Flag specifying the current user access permissions. The following values are possible:
Optional parameter. Set to Y by default (access permissions must be checked). |
See Also
Examples of use
<? /************************************************* Adding a web form *************************************************/ // create an array describing the image // contained in file on server $arIMAGE = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/web_form.gif"); $arIMAGE["MODULE_ID"] = "form"; $arFields = array( "NAME" => "Visitor form", "SID" => "VISITOR_FORM", "C_SORT" => 300, "BUTTON" => "Save", "DESCRIPTION" => "Please fill out the form", "DESCRIPTION_TYPE" => "text", "STAT_EVENT1" => "form", "STAT_EVENT2" => "visitor_form", "arSITE" => array("r1"), "arMENU" => array("en" => "Visitor Form"), "arGROUP" => array("2" => "15", "3" => "20"), "arIMAGE" => $arIMAGE ); // add new web form $NEW_ID = CForm::Set($arFields); if ($NEW_ID>0) echo "New Web form is added with ID=".$NEW_ID; else // error { // print error description global $strError; echo $strError; } ?>
<? // example of web form update, which parameters were visually // edited in administrative section $w = CGroup::GetList($v1, $v2, Array("ADMIN"=>"N"), $v3); $arGroups = array(); while ($wr=$w->Fetch()) $arGroups[] = array("ID"=>$wr["ID"], "NAME"=>$wr["NAME"]); $z = CLanguage::GetList($v1, $v2, array("ACTIVE" => "Y")); $arFormMenuLang = array(); while ($zr=$z->Fetch()) $arFormMenuLang[] = array("LID"=>$zr["LID"], "NAME"=>$zr["NAME"]); $rs = CSite::GetList(($by="sort"), ($order="asc")); while ($ar = $rs->Fetch()) { if ($ar["DEF"]=="Y") $def_site_id = $ar["ID"]; $arrSites[$ar["ID"]] = $ar; } if ((strlen($save)>0 || strlen($apply)>0) && $REQUEST_METHOD=="POST") { $arIMAGE_ID = $HTTP_POST_FILES["IMAGE_ID"]; $arIMAGE_ID["MODULE_ID"] = "form"; $arIMAGE_ID["del"] = ${"IMAGE_ID_del"}; $arFields = array( "NAME" => $NAME, "SID" => $SID, "C_SORT" => $C_SORT, "BUTTON" => $BUTTON, "DESCRIPTION" => $DESCRIPTION, "DESCRIPTION_TYPE" => $DESCRIPTION_TYPE, "FILTER_RESULT_TEMPLATE" => $FILTER_RESULT_TEMPLATE, "TABLE_RESULT_TEMPLATE" => $TABLE_RESULT_TEMPLATE, "STAT_EVENT1" => $STAT_EVENT1, "STAT_EVENT2" => $STAT_EVENT2, "STAT_EVENT3" => $STAT_EVENT3, "arIMAGE" => $arIMAGE_ID, "arSITE" => $arSITE, "arMAIL_TEMPLATE" => $arMAIL_TEMPLATE ); // меню $arMENU = array(); reset($arFormMenuLang); while (list(,$arrL)=each($arFormMenuLang)) { $var = "MENU_".$arrL["LID"]; global $$var; $arMENU[$arrL["LID"]] = $$var; } $arFields["arMENU"] = $arMENU; // access permission $arGROUP = array(); reset($arGroups); while (list(,$arrG)=each($arGroups)) { $var = "PERMISSION_".$arrG["ID"]; global $$var; $arGROUP[$arrG["ID"]] = $$var; } $arFields["arGROUP"] = $arGROUP; if ($ID = CForm::Set($arFields, $ID)) { if (strlen($strError)<=0) { if (strlen($save)>0) LocalRedirect("form_list.php?lang=".LANGUAGE_ID); else LocalRedirect("form_edit.php?ID=".$ID."〈=".LANGUAGE_ID); } } $DB->PrepareFields("b_form"); } ?>
© «Bitrix24», 2001-2024