In yii2 we can create form without create FormModel. Here we go
// in controller
public function actionForm()
{
$model = new \yii\base\DynamicModel([
'name', 'email', 'address'
]);
$model->addRule(['name','email'], 'required')
->addRule(['email'], 'email')
->addRule('address', 'string',['max'=>32]);
if($model->load(Yii::$app->request->post())){
// do somenthing with model
return $this->redirect(['view']);
}
return $this->render('form', ['model'=>$model]);
}
and then in form.php
<div class="form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'address') ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div><!-- form -->
wow how can upload photo in above example
Thanks for tutorial
Its gr8 . but how to upload image in this
@VivekYii
What do you mean? look this posting
How can we use in yii2 advance backend for frontend acccess
Hi
how can we upload single file to folder and information to database of backend
for access in frontend users.....
@VivekYii
yii2-upload-file
add config in common
'controllerMap' => [ 'file' => 'mdm\\upload\\FileController', // use to show or download file ],
Then you can access with
?r=file&id=$id
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.