Example #1
0
 /**
  * Initializes the widget.
  * This renders the form open tag.
  */
 public function init()
 {
     $this->csrf = Instance::ensure($this->csrf, '\\rock\\csrf\\CSRF', [], false);
     $this->request = Instance::ensure($this->request, '\\rock\\request\\Request');
     if (!empty($this->clientAction)) {
         $this->clientAction = Alias::getAlias($this->clientAction);
     }
     if (!isset($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     if (!isset($this->fieldConfig['class'])) {
         $this->fieldConfig['class'] = ActiveField::className();
         $this->fieldConfig['enableClientValidation'] = $this->enableClientValidation;
         $this->fieldConfig['validateOnChanged'] = $this->validateOnChanged;
     }
     $this->modelName = $this->model->formName();
     $this->options = $this->clientOptions($this->options);
     echo ActiveHtml::beginForm($this->action, $this->method, $this->modelName, $this->options);
 }
Example #2
0
 /**
  * Generates an appropriate input name for the specified attribute name or expression.
  *
  * This method generates a name that can be used as the input name to collect user input
  * for the specified attribute. The name is generated according to the @see Model::formName
  * of the model and the given attribute name. For example, if the form name of the `Post` model
  * is `Post`, then the input name generated for the `content` attribute would be `Post[content]`.
  *
  * See {@see \rock\widgets\ActiveHtml::getAttributeName()} for explanation of attribute expression.
  *
  * @param Model  $model     the model object
  * @param string $attribute the attribute name or expression
  * @return string the generated input name
  * @throws \rock\template\HtmlException if the attribute name contains non-word characters.
  */
 public static function getInputName($model, $attribute)
 {
     $formName = $model->formName();
     if (!preg_match('/(^|.*\\])([\\w\\.]+)(\\[.*|$)/', $attribute, $matches)) {
         throw new HtmlException('Attribute name must contain word characters only.');
     }
     $prefix = $matches[1];
     $attribute = $matches[2];
     $suffix = $matches[3];
     if ($formName === '' && $prefix === '') {
         return $attribute . $suffix;
     } elseif ($formName !== '') {
         return $formName . $prefix . "[{$attribute}]" . $suffix;
     } else {
         throw new HtmlException(get_class($model) . '::formName() cannot be empty for tabular inputs.');
     }
 }