diff --git a/en/14.3.md b/en/14.3.md index 6c9a7fd3..c164dd92 100644 --- a/en/14.3.md +++ b/en/14.3.md @@ -19,9 +19,15 @@ Although the procedure is not very complex, it usually requires a lot of boilerp ## Forms and validation +For developers, the general development process can be quite complex, but it's mostly repetitive work. Suppose a scenario arises where you suddenly need to add a form to your project, causing you to rewrite all of the local code tied in with the form. We know that `structs` are a very commonly used data structure in Go, and Beego uses them to its advantage for processing form information. + +First, we define a `struct` with fields corresponding to the fields in our form element. We can use `struct` tags which map to the form element, as shown below: + +First define a struct that corresponds to when developing Web applications, a field corresponding to a form element, defined by using a struct tag corresponding to the element information and authentication information, as shown below: + For developers, the general development process is very complex, and mostly are repeating the same work. Assuming a scenario project suddenly need to add a form data, then the local code of the entire process needs to be modified. We know that Go inside a struct is a common data structure, so beego the form struct used to process form information. -First define a developing Web applications corresponding struct, a field corresponds to a form element, through the struct tag to define the corresponding element information and authentication information, as follows: +First define a `struct` with fields corresponding to our form element, using `struct` tags to define corresponding element and authentication information, like so: type User struct{ Username string `form:text,valid:required` @@ -31,7 +37,7 @@ First define a developing Web applications corresponding struct, a field corresp Introduce string `form:textarea` } -Struct defined in this way after the next operation in the controller +After defining our `struct`, we can add this action in our controller: func (this *AddController) Get() { this.Data["form"] = beego.Form(&User{}) @@ -39,14 +45,14 @@ Struct defined in this way after the next operation in the controller this.TplNames = "admin/add.tpl" } -This form is displayed in the template +The form is displayed in our template like so: