[
// ...
'admin' => 'site/login',
];
<form method="post">
<input name="name">
<input name="question[0][name]">
<input name="question[0][answer][]">
<input name="question[0][answer][]">
<input name="question[0][correct_answer]">
<input name="question[1][name]">
<input name="question[1][answer][]">
<input name="question[1][answer][]">
<input name="question[1][correct_answer]">
<input type="submit" value="save">
</form>
var_dump($_POST);
array (size=2)
'name' => string '' (length=0)
'question' =>
array (size=2)
0 =>
array (size=3)
'name' => string '' (length=0)
'answer' =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
'correct_answer' => string '' (length=0)
1 =>
array (size=3)
'name' => string '' (length=0)
'answer' =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
'correct_answer' => string '' (length=0)
'visibleButtons' = [
'update' => Yii::$app->user->can('updateOwnPost')
'delete' => Yii::$app->user->can('updateOwnPost')
]
<input type="text" name="firstname" value="<?=($_POST['firstname']) ?? '';?>" required>
$_POST['firstname']='"</input><script src="scripts.js"></script>'
yii\widgets\ActiveField
, а точнее методы в нём:public $template = "{label}\n{icon}\n{input}\n{hint}\n{error}";
public function render($content = null)
{
if ($content === null) {
if (!isset($this->parts['{input}'])) {
$this->textInput();
}
// добавить это
if (!isset($this->parts['{icon}'])) {
$this->icon();
}
if (!isset($this->parts['{label}'])) {
$this->label();
}
if (!isset($this->parts['{error}'])) {
$this->error();
}
if (!isset($this->parts['{hint}'])) {
$this->hint(null);
}
$content = strtr($this->template, $this->parts);
} elseif (!is_string($content)) {
$content = call_user_func($content, $this);
}
return $this->begin() . "\n" . $content . "\n" . $this->end();
}
public function icon($content, $options = [])
{
$this->parts['{icon}'] = Html::tag('i', null, ['class' => 'icon-'.$this->attribute];
return $this;
}
$form = ActiveForm::begin([
'fieldClass' => 'my\widgets\ActiveField'
]);