Version: current

     1 <?php
     2 /**
     3  * Добавляет возможность показа UserDefinedForm по url на любых страницах
     4  *
     5  * @author dvp
     6  */
     7 class ShowUserFromExtension extends Extension {
     8
     9     /**
    10      * Показывает стороннюю UserDefinedForm на странице
    11      *
    12      * @param string $url       url страницы с UserDefinedForm
    13      * @param string $template  шаблон для вставки (без шаблона возвращается просто форма)
    14      *
    15      * @return string - html код формы
    16      */
    17     function ShowUserForm($url, $template='', $suffix='popup') {
    18         if (!class_exists('UserDefinedForm_Controller'))
    19             return '';
    20         $form = (is_numeric($url)) ? SiteTree::get_by_id('UserDefinedForm', intval($url)) : SiteTree::get_by_link($url);
    21
    22         if ($form && $form->ClassName == 'UserDefinedForm') {
    23             $controller = new UserDefinedForm_Controller($form);
    24             $controller->formInit();
    25             $controller->suffix = $suffix;
    26             $form = $controller->Form();
    27             $form->dataFieldByName('HtmlIDSuffix')->setValue($suffix);
    28             $form->setHtmlID($controller->generateFormID());
    29             $data = Session::get("FormInfo.{$form->FormName()}.data");
    30             if(is_array($data)) $form->loadDataFrom($data);
    31
    32             if ($template) {
    33                 return $controller->renderWith($template, array(
    34                     'FormID' => $controller->generateFormID(),
    35                     'Form' => $form
    36                 ));
    37             }
    38             return $form;
    39         }
    40     }
    41
    42 }
    43

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -