Documentation

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:
  • NAME* - web form title;
  • SID* - web form symbol identifier;
  • C_SORT - sorting index;
  • BUTTON - letters on the button when creating or editing the result;
  • USE_RESTRICTIONS - use restrictions;
  • RESTRICT_USER - maximum number of results from user;
  • RESTRICT_TIME - minimal time interval between the results;
  • DESCRIPTION - description;
  • DESCRIPTION_TYPE - type of description. The following values are possible:
    • text - text;
    • html - HTML code.
  • FILTER_RESULT_TEMPLATE - path from root to file to be used to show filter of results in the module administrative section;
  • TABLE_RESULT_TEMPLATE - path from root to file to be used to show table of results in the module administrative section;
  • STAT_EVENT1 - EVENT1 identifier for the event type for the "Statistics" module;
  • STAT_EVENT2 - EVENT1 identifier for the event type for the "Statistics" module;
  • STAT_EVENT3 - additional event event parameter for the "Statistics" module;
  • arIMAGE - array describing the web form image. The following array keys are available:
    • name - file name;
    • size - file size;
    • tmp_name - temporary path on the server;
    • type - type of uploaded file;
    • del - if Y, the image is to be deleted;
    • MODULE_ID - "Web Form" module identifier ("form").
  • arSITE - array of site identifiers to attach this web form:
    array("ID_SITE_1", "ID_SITE_2", ...)
  • arMAIL_TEMPLATE - array of mail template IDs, associated with this web form:
    array("ID_TEMPLATE_1", "ID_TEMPLATE_2", ...)
  • arMENU - array of menu titles. The menu is displayed in the administrative section and leads to this web form results:
    array("ID_LANGUAGE_1" => "MENU_1", "ID_LANGUAGE_2" => "MENU_2", ...)
  • arGROUP - array describing access permissions of user groups for this web form:
    array("ID_GROUP_1" => "PERMISSION_1", "ID_GROUP_2" => "PERMISSION_2", ...)
* - required to be filled.
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:
  • Y - check access permissions;
  • N - do not check access permissions.
To update web form parameters, access permission with [30] Full access is required for the web form, specified in the parameter form_id. To add new web form, [W] Full access permission for Web forms module is required.

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