Sunday, January 2, 2022

[FIXED] How can I add extra form data in yii ActiveForm?

Issue

I would like to know how can I add data to an ActiveForm like this:

<?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'name') ?>

    <?= $form->field($model, 'email') ?>

    <div class="form-group">
        <?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
    </div>
<?php ActiveForm::end(); ?>

.

  $data = ["username"=>"test"] as property "username"

I would like to send something like {name:name, email:email, ..., username:data}


Solution

you can use hidden input of \yii\helpers\Html class like follows:

<?= Html::hiddenInput('username', $value = $data['username']) ?>

or if you want it to be filled by users, you can use like this:

<?= Html::textInput('username') ?>


Answered By - Mahsa

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.