D
D
Daniil Sidorov2018-09-05 13:36:01
Yii
Daniil Sidorov, 2018-09-05 13:36:01

How to handle custom forms in yii2?

Hello. Please help me figure it out. How to process forms in yii2? Why do you need ActiveForm at all?
I have a form that looks like this.

Open Image
d22ffeca33f78e02d8b39644210b6c65.png

There is a stylized input type="range" on the form.
<label for="range">Приоритет:</label>
                    <input type="range" id="range" min="1" max="3" step="1" value="0" data-slideout-ignore/>
                    <div class="labels">
                        <span class="left active" data-priority="1">низкий</span>
                        <span class="center" data-priority="2">средний</span>
                        <span class="right" data-priority="3">высокий</span>
                    </div>

When the value changes, the items below become active (Jquery).
How to do similar with ActiveForm. And why is it needed at all?
Usually I did this: I did not use ActiveForm at all. I just took the data with Ajax on click and transferred it to the desired controller, which already added the values ​​​​to the database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-09-05
@DaniLaFokc

Why do you need ActiveForm at all?

In order not to write validation on js with handles.
It is necessary to process not forms, and the data which they send.
ActiveForm exists for convenience, if in your case it is not convenient - do not use it.
What exactly? Would you like this form? Or maybe you could be more specific. What exactly can't be done with the ActiveForm widget? inputtype="range"? Usually, a separate widget is made and used like this:
echo $form->field($model, 'attribute')->widget(SomeMyWidget::classname(),[
'some' => 'config'
]);

You get the opportunity to form any html in the widget, connect your assets (pictures, fonts, css, js and whatever you like). At the same time, regular validation works, etc.
Everything is in the documentation: https://www.yiiframework.com/doc/guide/2.0/en/stru... including examples: https://www.yiiframework.com/extension/yiisoft/yii2-jui

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question