Use the Yii form model and submit form data in array form. According to the description in the Yii document, the general process of Yii processing forms is: in a small project just now, Yii wants to submit form information using ajax and verify and save the information, you do not want to use the hidden iframe to do the following:
In a small project just now, I want to use ajax to submit form information and verify and save the information, and do not want to use hidden iframe for refreshing new submissions. In addition, the action can be used to validate model classes, let's think of the form array submission method. for example:
Form code:
After submission, you can directly use $ _ POST ['arr'] to obtain the submitted data. $ _ POST ['arr'] is:
0] =>1] =>2] =>
Similarly, if you use the following form to submit:
$ _ POST ['arr:
3] =>6] =>8] =>
Of course, two-dimensional arrays can also be submitted:
$ _ POST ['arr:
0] => =>1] => =>2] => =>
If the key of the first sub-array is not set, each value is added to arr when an array is generated. if you want to save the information in an array, add a key value as follows:
$ _ POST ['arr:
=> =>=>=> =>=>
The following is an example of submitting a form using ajax and verifying the form using the yii form model. The first part is the model class. there is only the simplest verification method:
''),
It is interesting to find that when the model class sets the parameter verification method, it needs to set rules for each public parameter. if there are parameters with no rules set, after the form value in $ _ POST is assigned a value to the model, the parameter value without the rule is null.
Obtain the parameters submitted by the form in the action and verify the parameters:
$model->attributes = ['form'(-> = ->......
Finally, the code for the front-end form submission, using jquery:
info = = { 'form[landing_title]''form[landing_content]''form[landing_position]' url = "..."
In a small project just now, users want to use ajax to submit form information and verify and save the information, and do not want to use hidden iframe to do this...