Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Yii Framework form Model usage and how to submit form data in an Array form tutorial

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the "tutorial on the use of yii Framework form Model and the method of submitting form data in Array form". In daily operation, it is believed that many people have doubts about the use of yii Framework form model and the method tutorial of submitting form data in array form. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer your doubts about how to use the form model in yii framework and how to submit form data in array form. Next, please follow the editor to study!

As described in the Yii document, the general process for Yii to process a form is:

Create the model class corresponding to the form and set the field validation rules

Create the action corresponding to the form submission and process the submitted content

Create a form form in the view

In a small project just now, you want to use ajax to submit form information and verify and save it, but you don't want to use hidden iframe to do no refresh submission, and action can use model class verification methods, so you want to use form array submission, for example:

Form Code:

The copy code is as follows:

After submission, you can directly use $_ POST ['arr'] to obtain the submitted data. $_ POST [' arr'] is:

The copy code is as follows:

Array

(

[0] = > a

[1] = > b

[2] = > c

)

Similarly, if you submit using the following form:

The copy code is as follows:

$_ POST ['arr'] is:

Array

(

[3] = > a

[6] = > b

[8] = > c

)

Of course, you can also submit a two-dimensional array:

The copy code is as follows:

$_ POST ['arr'] is:

Array

(

[0] = > Array

(

[name1] = > a

)

[1] = > Array

(

[name2] = > b

)

[2] = > Array

(

[name3] = > c

)

)

Here is a problem. If you do not set the key of the first subarray, each value will be added in the arr when the array is generated. If you want to save the information in an array, add a key value, as follows:

The copy code is as follows:

$_ POST ['arr'] is:

Array

(

[a] = > Array

(

[name1] = > A1

[value1] = > a2

)

[B] = > Array

(

[name2] = > b1

[value2] = > b2

)

)

Here is an example of submitting a form with ajax and validating it with a yii form model, starting with the model class section, where there is only the simplest verification method:

The copy code is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report