L
L
Lander2015-07-01 17:22:34
Yii
Lander, 2015-07-01 17:22:34

What is the great point of adding hidden fields to ActiveForm?

I have not been familiar with Yii2 for a long time. Gradually I try to master ActiveForm. Now I came across an interesting thing, in the code I write:

<?= $form->field($model, 'price')->radio(['value' => 'common', 'id' => 'price-common', 'label' => 'Обычная цена']); ?>

as a result on the page I get:
<div class="form-group field-orderform-price required">
<input type="hidden" name="OrderForm[price]" value="0"> <!--Вот эта строка непонятна-->
<label><input type="radio" id="price-common" name="OrderForm[price]" value="common"> Обычная цена</label>
<div class="help-block"></div>
</div>

Accordingly, in POST, a bunch of these zero hidden-fields go to the server, but I don’t need them there. Is this some kind of ingenious thing that I don't understand, or should ActiveForm still not add fields that it is not asked to add?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
matperez, 2015-07-01
@usdglander

I don’t fully understand what the cymes is, but the dock says this:
uncheck: string, the value associated with the uncheck state of the radio button. If not set, it will take the default value '0'. This method will render a hidden input so that if the radio button is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input. If you do not want any hidden input, you should explicitly set this option as null.
As I understand it, this allows you to override the values ​​​​that come to the server if the checkbox is not checked and not affected in the process of filling out the form at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question