Contao\Form::generate PHP Метод

generate() публичный Метод

Remove name attributes in the back end so the form is not validated
public generate ( ) : string
Результат string
    public function generate()
    {
        if (TL_MODE == 'BE') {
            /** @var BackendTemplate|object $objTemplate */
            $objTemplate = new \BackendTemplate('be_wildcard');
            $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['CTE']['form'][0]) . ' ###';
            $objTemplate->id = $this->id;
            $objTemplate->link = $this->title;
            $objTemplate->href = 'contao/main.php?do=form&table=tl_form_field&id=' . $this->id;
            return $objTemplate->parse();
        }
        if ($this->customTpl != '' && TL_MODE == 'FE') {
            $this->strTemplate = $this->customTpl;
        }
        return parent::generate();
    }

Usage Example

Пример #1
0
 /**
  * Generate a form and return it as string
  *
  * @param mixed  $varId     A form ID or a Model object
  * @param string $strColumn The column the form is in
  *
  * @return string The form HTML markup
  */
 public static function getForm($varId, $strColumn = 'main')
 {
     if (is_object($varId)) {
         $objRow = $varId;
     } else {
         if ($varId == '') {
             return '';
         }
         $objRow = \FormModel::findByIdOrAlias($varId);
         if ($objRow === null) {
             return '';
         }
     }
     $objRow->typePrefix = 'ce_';
     $objRow->form = $objRow->id;
     $objElement = new \Form($objRow, $strColumn);
     $strBuffer = $objElement->generate();
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getForm']) && is_array($GLOBALS['TL_HOOKS']['getForm'])) {
         foreach ($GLOBALS['TL_HOOKS']['getForm'] as $callback) {
             $strBuffer = static::importStatic($callback[0])->{$callback}[1]($objRow, $strBuffer, $objElement);
         }
     }
     return $strBuffer;
 }