active-form

Yii2 model load does not work as expected

六眼飞鱼酱① 提交于 2019-12-12 04:35:54
问题 My question may look like the following question: yii2 - model load function does not set some model attributes However, the case here is different due to dealing with Many to Many relation through junction table. For instance, I have three tables, Jobs , Eqtypes and the junction table Eqtype_jobs . I want to relate some Eqtypes to a current Job using simple activeform using multiple select dropDownList . The following is the code that I have in, the controller and the view: //the controller

How to solve Bad Request (#400) Unable to verify your data submission in yii2?

给你一囗甜甜゛ 提交于 2019-12-11 03:03:24
问题 I have got this error, when submit the form: Bad Request (#400) Unable to verify your data submission. I have got <?= Html::csrfMetaTags() ?> in the layout. I think, that this problems I have, because I use datepicker. Form create with ActiveForm. What I must to do? Here is code of the form: <? $form2 = ActiveForm::begin(['id' => 'user-univer']); echo $form2->field($model2, 'university')->label('Input university name:'); echo $form2->field($model2, 'degree')->label('Input your education

Radio Button group in separate place in yii2

江枫思渺然 提交于 2019-12-05 10:58:16
So, I want to have two radio button in separate place, I have been trying to search for the solution and everyone suggests to use radiolist which is not possible in my case. If I put it like this (work_part_time button) : (below) <div class="row"> <div class="col-sm-2"> <?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?> </div>- <div class="col-sm-3"> <?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => 'Hour/Week'])->label(false)?> </div> <div class="col-sm-3"> <?= $form->field($model, 'part_time_rate')->textInput(['type' =>

yii2: make checkbox to be checked

淺唱寂寞╮ 提交于 2019-12-05 03:42:23
I am using Yii2 framework and I'd like to generate an html code like this <input type="checkbox" id="queue-order" name="Queue[order]" value="1" checked> in a view which uses ActiveForm. I've tried echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => true]); as well as echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => 'checked']); but desired string "checked" does not appear in the generated html code. Strangely enough, if I substitute "checked" with "selected" echo $form->field($model, 'order') ->checkBox([

Yii2 Insert multiple records of a same table

旧街凉风 提交于 2019-12-03 15:04:26
问题 I Have my model with 2 fields Product.php: [['ID_PRODUCT'], 'integer'], [['NAME_PRODUCT'], 'string'], my Controller ProductController.php: public function actionCreate() { $model = new Product(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->ID_PRODUCT]); } else { return $this->render('create', [ 'model' => $model, ]); } } And i want insert many times the same table with ActiveForm: <?php $form = ActiveForm::begin(); ?> <?=

Yii2 Insert multiple records of a same table

十年热恋 提交于 2019-12-03 03:58:37
I Have my model with 2 fields Product.php: [['ID_PRODUCT'], 'integer'], [['NAME_PRODUCT'], 'string'], my Controller ProductController.php: public function actionCreate() { $model = new Product(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->ID_PRODUCT]); } else { return $this->render('create', [ 'model' => $model, ]); } } And i want insert many times the same table with ActiveForm: <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'ID_PRODUCT')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'NAME

Yii2 activeform ajax submit and validation

百般思念 提交于 2019-12-03 00:49:24
Currently to achieve ajax submit and validation at the same time. I'm using custom function like: $('.edit_form').submit(function (e) { e.preventDefault(); var form = $(this); var formData = $(this).serialize(); if (form.find('.has-error').length) { return false; } $.ajax({ url: form.attr("action"), type: form.attr("method"), data: formData, success: function (data) { ... }, error: function () { alert("Something went wrong"); } }); }); And here is php side, for validation my config looks like that: $form = ActiveForm::begin([ 'id' => "some_form", 'action' => ['user/edit'], 'options' => ['class

How to set Yii2's ActiveForm checkbox in checked state?

此生再无相见时 提交于 2019-12-01 18:07:51
I'm looking for a simple solution for a "checked" state for the Yii2 ActiveForm checkbox control and I can't find a solution how to set it. I cant find any examples in the documentation. I've tried to manipulate the rendering code <?= $form->field($model, 'name')->checkbox()->label('Hi'); ?> But it seems I need to modify the ActiveForm itself. How to make checkbox checked by default? Ok, I've debbuged a while and found a solution, it lies in the guts of BaseHtml.php at line 1359 in activeCheckbox() function $checked = "$value" === "{$options['value']}"; It checks for the default value of the

jQuery(…).activeform is not a function in Yii

◇◆丶佛笑我妖孽 提交于 2019-12-01 16:46:17
I am developing a project with Yii. I need to use jquery ui on many pages of site. So I add jquery core library and jquery ui library in the layout of site to have access to them on all the pages. But it causes problem on the pages which have a form (active form). I see this error on the firebug : jQuery(...).activeform is not a function why is it so? How can I resolve it? Thank you. If you include jQuery core libraries manually in your layout file, it could be possible that jQuery gets loaded a second time and overrides the original jQuery object which had the Yii plugins attached. You should

jQuery(…).activeform is not a function in Yii

China☆狼群 提交于 2019-12-01 15:31:09
问题 I am developing a project with Yii. I need to use jquery ui on many pages of site. So I add jquery core library and jquery ui library in the layout of site to have access to them on all the pages. But it causes problem on the pages which have a form (active form). I see this error on the firebug : jQuery(...).activeform is not a function why is it so? How can I resolve it? Thank you. 回答1: If you include jQuery core libraries manually in your layout file, it could be possible that jQuery gets