A
A
Al3x4kov2017-01-22 17:36:36
Yii
Al3x4kov, 2017-01-22 17:36:36

How to write down the username on clicking the checkbox?

Friends, please help.
There is

<?=$form->field($checklist, 'agreed')
                ->checkbox([
                    'label' => "Чекнул пункт: <b style=\"color:red\">".$checklist->check_user."</b>",
                    'labelOptions' => [
                        'style' => 'padding-left:20px;'
                    ],
                    'disabled' => false
                ]);
            ?>

I understand that using php the username can be obtained as:
Yii::$app->user->identity->username
But how can I assign the value of $checklist->check_user using js I can’t guess.
This is necessary in order to then enter the value of check_user into the database, in addition to the value agreed ( 1 ? 0 )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-01-22
@slo_nik

Good evening.
This is how you can handle the "click" on the checkbox

<?= 
      $form->field($model, 'attribut')->checkbox([
           'onclick' => '
                  alert($(this).val())
            '
        ])
    ?>

Look at the source code of the page. There should be a hidden field nearby. That's where you put the user id.
Although I didn't fully understand the question.
Did the user go to the page, check the checkbox, and submit the form?

M
Maxim Timofeev, 2017-01-25
@webinar

But I can't figure out how to assign a value to $checklist->check_user using js.

Why do you need js? If you need to get the user in the controller that processes your form, it is not at all necessary to pass it there. Because Yii::$app->user->identity->username in the controller will return it to you. Why is it in the form?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question