2

i have a gridview of checkin model with checkbox action column and on the same view i have form of model message with 2 field message and fileinput but i want to send one more data on the submit button click of message model form which is the keys of checkbox.

How can i so that? it can be done only via javascript or there is some other technique as well?

here is my grid and view code

<div class="row">
<p>
    <?php $form = ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data']]); ?>

    <div class="form-group col-xs-3 col-lg-3">
        <?= $form->field($model, 'message')->textarea(['rows' => 6]) ?>
    </div>
    <div class="form-group col-xs-3 col-lg-3">
        <?= $form->field($model, 'file')->fileInput() ?>

        <div class="form-group">
        <?= Html::submitButton('Send', ['class' => 'btn btn-danger','id'=>'sendMessage']) ?>
        </div>
    </div>

    <?php ActiveForm::end(); ?>



  </p>
</div>
<div class="checkin-index">

    <h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>

 <?php Pjax::begin(['id' => 'checkin-grid', 'timeout' => false]); ?>

 <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'showOnEmpty'=>true,
        'columns' => [
            [
                'class' => 'yii\grid\CheckboxColumn',
            ],
            [
                'attribute' => 'user_id',
                'label' => 'Email',
                'value' => 'users.email',
            ],
            'user_type',
        ],
    ]);
 ?>
<?php Pjax::end(); ?>

And here is my checkin/index code where i can access the message and fileinput but i want list of keys as well... So user must check at least one row before sending message

 public function actionIndex()
{
    $model = new Message();
    $searchModel = new CheckinSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
        'model' => $model,
    ]);
}
2
  • Have you tried putting the gridview inside the form? Commented Oct 2, 2015 at 11:59
  • @topher no i havent tried that but i am trying that now... Commented Oct 5, 2015 at 22:23

1 Answer 1

1

You can extend your Message model adding the fields you need

class Message extends \yii\db\ActiveRecord
{

    public $yourField;    

    public static function tableName()
    {
       ...
    }

this way in your model you have one more field not mapped to database and yon can use for your need....

When you submit your value, the submit related action you shuold manage the models like this way

   $models = $dataProvider->getModels();
   if (Model::loadMultiple($models, Yii::$app->request->post()) && Model::validateMultiple($models)) {  

    ...... your code for models managemnt



  }

F

Sign up to request clarification or add additional context in comments.

3 Comments

yeah but how can i send the data of gridview checked column via that?
when you submit your data. In this case the submit related action should manage the models whit load multiple equivalent function based op posted value.
I have update the answer... I hope this could be useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.