Shringiraj Dewangan
Shringiraj Dewangan

Reputation: 784

how to change form input name prefix in yii2 active form

code is here

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

and it will gives

<input type="text" id="machine-machine_name" class="form-control" name="Machine[machine_name]" maxlength="255" aria-required="true" autocomplete="off">

and i want to change

name="Machine[machine_name]" 

to

name="something_else[machine_name]"

something_else is dymanic for all form fields

Upvotes: 0

Views: 1638

Answers (1)

rob006
rob006

Reputation: 22174

This prefix comes from formName(). You can override this method in your model (Machine) to provide custom prefix:

public function formName() {
    return 'something_else';
}

Upvotes: 5

Related Questions