$model = Payment::find()->where(['user_id' => $id])->one();
$model->pre_auth_payment = "$28.25";
$model->scenario = "credit_card_form";
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if($model->pre_auth_payment == 0)
$model->scenario = "credit_card_form";
else
$model->scenario = "bank_account_form";
$model->save();
return $this->redirect(['update', 'id' => $model->user_id, 'step'=> 3]);
} else {
return $this->render('update', [
'model' => $model,
'step'=>$step
]);
}
[['user_id', 'payment_method', 'credit_card_number', 'credit_card_expr', 'credit_card_cvv', 'credit_card_info','type_pay'], 'required', 'when' => function($model) {
return $model->type_pay == 0;
}],
[[ 'pre_auth_payment', 'day_month', 'transit_number', 'institution_id', 'account_num'], 'required', 'when' => function($model) {
return $model->type_pay == 1;
}],
<code>
public function rules()
{
return [
[['user_id', 'payment_method', 'credit_card_number', 'credit_card_expr', 'credit_card_cvv', 'credit_card_info','type_pay'], 'required', 'when' => function($model) {
return $model->type_pay == 0;
},'whenClient' => "function (attribute, value) {
return $('input[name=\"Payment[type_pay]\"]:checked').val() == 0;
}"],
[[ 'pre_auth_payment', 'day_month', 'transit_number', 'institution_id', 'account_num'], 'required', 'when' => function($model) {
return $model->type_pay == 1;
},'whenClient' => "function (attribute, value) {
return $('input[name=\"Payment[type_pay]\"]:checked').val() == 1;
}"],
[['user_id'], 'integer'],
[['type_pay'], 'required'],
[['payment_method', 'credit_card_number', 'credit_card_expr', 'credit_card_cvv', 'credit_card_info', 'pre_auth_payment', 'day_month', 'transit_number', 'institution_id', 'account_num'], 'string', 'max' => 255]
];
}