I am new to Yii2 and tried to work out the tutorials first.
I simply tried to add a new field (name: group) to the "Working with Forms" Guide referring to this webpage: http://ift.tt/1pvE0Gd.
But user input from the added field doesn´t appear in the model.
The model:
class EntryForm extends Model
{
public $name;
public $email;
public $group; // additional attribute !!!!!!!!!!!
public function rules()
{
return [
[['name', 'email'], 'required'],
['email', 'email'],
];
}
}
The Site Controller stays without any changes to the guide.
Entry-Form:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->label('Your Name') ?>
<?= $form->field($model, 'email')->label('Your E-Mail address') ?>
<?= $form->field($model, 'group')->label('Your Group name') ?> <!-- additional input !!!!!!!!!!! ->
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
Entry Confirm:
...
<ul>
<li><label>Name</label>: <?= Html::encode($model->name) ?></li>
<li><label>Email</label>: <?= Html::encode($model->email) ?></li>
<li><label>Group</label>: <?= Html::encode($model->group) ?></li> <!--additional attribute !!!!!!!!!!! ->
</ul>
...
Notes:
Except the additional field "group", everything works fine.
User input in the "group" field appears in $_POST as expected.
But it does not appears in the model if I call $model->getAttributes()
I already checked the documentation of model->load() but couldn`t find any hint.
Thanks a lot for any help.
Aucun commentaire:
Enregistrer un commentaire