According to the description in the Yii documentation, the general process of Yii processing forms is:
Create the model class corresponding to the form, set the field validation rules
Create the action corresponding to the form submission, and process the submitted content
Create the form form in the view
In a small project just now, I want to use Ajax submits the form information and verifies and saves it. I don’t want to use a hidden iframe for non-refresh submission, and the verification method of the model class can be used in the action. I thought of using the form array submission method. For example:
form code:
Array
(
[0] => Array
(
[name1] => a
)
[1] => Array
(
[name2] => b
)
[2] => Array
(
[name3] => c
)
)
There is a problem here. If you do not set the key of the first sub-array, each value will be added to arr sequentially when generating the array. If you want to save the information in an array, just add a key value. , as follows:
Array
(
[a] => Array
(
[name1] => a1
[value1] => a2
)
[ b] => Array
🎜>
Posted below is an example of using ajax to submit a form and verifying it using the yii form model. The first is the model class part, which only has the simplest verification method:
class LandingForm extends CFormModel{ public $landing_title; public $landing_content; public $landing_position;
I found something interesting. When setting the parameter verification method, the model class needs to set rules for each public parameter. If there are parameters for which rules are not set, use the form value in $_POST to assign values to the model. After that, the parameter value of the unset rule will be empty
Get the parameters submitted by the form in action and verify:
$model = new LandingForm;
var info = new Object();
http://www.bkjia.com/PHPjc/763016.html
www.bkjia.com
http: //www.bkjia.com/PHPjc/763016.html