The following may be the form data to be submitted {code ...} I intend to write an OrderFormmodel to verify the data. products corresponds to a model, and there is also a model for Form Verification marketing, there is also a Form Verification OrderForm rules should... the following may be the form data to be submitted:
php
Array( [products] => Array ( [0] => Array ( [product_id] => 12 [product_sku] => 5614546542 [quantity] => 1 [price] => 34.00 ) [1] => Array ( [product_id] => 12 [product_sku] => 5614546542 [quantity] => 2 [price] => 34.00 ) [2] => Array ( [product_id] => 12 [product_sku] => 5614546542 [quantity] => 1 [price] => 34.00 ) ) [marketing] => Array ( [0] => Array ( [coupon] => 34sdhs56aj45dh56 [provider] => 1 ) [1] => Array ( [coupon] => 33454545324236 [provider] => 2 ) ) [shop_id] => 100 [member_card] => 3423432423123 [submittime] => 2015-2-3 9:52:09)
I plan to write an OrderForm model to verify the data;
Products corresponds to a model with form verification.
Marketing also corresponds to a model with form verification.
How to write the rules of OrderForm to implement the rules of the products variable corresponding to the products model;
The marketing variable corresponds to the rules in the marketing model;
Reply content:
The following may be the form data to be submitted:
php
Array( [products] => Array ( [0] => Array ( [product_id] => 12 [product_sku] => 5614546542 [quantity] => 1 [price] => 34.00 ) [1] => Array ( [product_id] => 12 [product_sku] => 5614546542 [quantity] => 2 [price] => 34.00 ) [2] => Array ( [product_id] => 12 [product_sku] => 5614546542 [quantity] => 1 [price] => 34.00 ) ) [marketing] => Array ( [0] => Array ( [coupon] => 34sdhs56aj45dh56 [provider] => 1 ) [1] => Array ( [coupon] => 33454545324236 [provider] => 2 ) ) [shop_id] => 100 [member_card] => 3423432423123 [submittime] => 2015-2-3 9:52:09)
I plan to write an OrderForm model to verify the data;
Products corresponds to a model with form verification.
Marketing also corresponds to a model with form verification.
How to write the rules of OrderForm to implement the rules of the products variable corresponding to the products model;
The marketing variable corresponds to the rules in the marketing model;
First, create the required Model, and add the 'attribute that will save the value submitted by the form' and the corresponding verification rules/scenarios.
Load the Model to the view and specify the Model corresponding to the attribute when creating each form item, for example:$form->field($marketModel, 'market')->textinput();
Submit the form and follow the steps below to load, verify, and save it.
Refer to the steps in the official documentation
1. instantiate model classes
2. populate the models attributes with input data
3. validate all models
4. If validation passes for all models, save them
5. If validation fails or no data has been submitted, display the form
By passing all model instances to the view