A
A
Alexander2017-07-04 21:32:19
Yii
Alexander, 2017-07-04 21:32:19

Will validation work in yii2 without ActiveForm?

Good day! Will validation work in the model without using the ActiveForm class? The matter is that I use ajax, and pjax built in ActiveFrom does not suit me. If it doesn't work without ActiveForm, then I'll put the question differently. If I hang an event on the form and send an ajax request to the controller, will the data get into the model in its public properties?
I read that validation is completely tied to ActiveFrom. So I'm thinking of trying to use the validation built into yii or to score and check each parameter on bare php? Not long ago I began to study yii, and so far I don’t understand whether validation will work if the form is sent by Ajax.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander, 2017-07-05
@BugFixMan

Found a way to solve my problem. Mass assignment helped me. handy thing)
cc99e15d6c7f45bcb0c11d8dc795c4a5.png

D
Dmitry, 2017-07-04
@slo_nik

Good evening.
Yes, they will.
Yes, it will work.
Read about ajax validation.
Help link .

A
Andrey Pavlenko, 2017-07-04
@Akdmeh

ActiveForm is the same forms, but with steroids. All the advantages of this widget come down to automatic validation of most standard Yii validators on the client side + the ability to AJAX validation + automated highlighting of form errors from previous requests.
You can not use ActiveForm, but use either pure HTML, or the \yii\helpers\HTML helper, and add the handlers you need yourself, and leave only server-side validation for Yii2.
In general, in Yii2 discussions, everything is moving towards the fact that they will gradually move all these FrontEnd widgets into separate packages, and Yii2 will focus on the "server" code. So if you don't need to use ActiveForm, you are free to use your frontend technologies.
A number of amendments at once. Learn Yii2 input name generation - saves a lot of time. The bottom line is that they use the default "namespaces" to multisubmit multiple forms and code order. For example, the name of an input tag for a news headline might be called News[header], where the first part is usually the name of the class, unless the behavior is overridden in the class by the formName method, and the name of the field in brackets.
This simplifies the validation of several different models.
The "table entry" is a little more complicated, but this already directs you to the documentation.

M
Maxim Timofeev, 2017-07-04
@webinar

I read that validation is completely tied to ActiveFrom

Only client. Validation has 2 parts, roughly speaking. 1 - on the server, 2 in the form of js scripts that the active form connects. So in the case of ajax, it is not at all necessary to use activeForm, although activeForm implies an option with ajax validation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question