Fix translation for section "Forms and validation" in 14.3.md

This commit is contained in:
Anchor
2015-02-16 22:01:27 -08:00
committed by James Miranda
parent 1e1e27cef9
commit c011679c21

View File

@@ -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:
<h1>New Blog Post</h1>
<form action="" method="post">
{{.form.render()}}
</form>
Above we defined the entire first step to display the form from the struct process, the next step is the user fill out the information, and then verify that the server receives data, and finally into the database.
Above, we've defined the entire first step of displaying a form mapped to a `struct`. The next step is for users to fill in their information and submit the form, after which the server will receive the data and verify it. Finally, the record will be inserted into the database.
func (this *AddController) Post() {
var user User