Answer the question
In order to leave comments, you need to log in
How to accept the result of a dropDownList?
Good afternoon!
I am creating a dropdown list.
<?= $f->field($form, 'block')->dropDownList([
7 => '7 дней',
14 => '14 дней',
30 => '30 дней',
0 => 'Полная',
])->label('Срок'); ?>
public function addBlock($user) {
var_dump($this->block);die;
}
<?php
namespace app\models;
use Yii;
use yii\base\Model;
class BlockForm extends Model {
public $block;
public $reason;
public function rules() {
return [
['reason', 'required', 'message' => 'Укажите причину блокировки'],
];
}
public function addBlock($user) {
//$time = time() + 60*60*24*$this->block;
var_dump($this->block);
var_dump($this->reason);die;
/*$block = new Block();
$block->iduser = $user->id;
$block->who = Yii::$app->user->identity->id;
$block->reason = $this->reason;
$block->time = time();
if($this->block > 0){ $block->timeblock = $time; }
else { $block->timeblock = 0; }
return $block->save();*/
}
}
public function actionBlock() {
$form = new BlockForm;
$id = Yii::$app->request->get('id');
$user = User::findOne($id);
if($form->load(Yii::$app->request->post()) && $form->validate() && $form->addBlock($user)) {
//var_dump($form); die;
//return $this->redirect('/admin/user/blockall');
}
return $this->render('block', [
'form' => $form,
'id' => $id,
'user' => $user,
]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question