|
1 | 1 | ## How to work with WebForms Core in GO |
2 | 2 |
|
3 | | -To use WebForms Core, first copy the WebForms class file in this directory to your project. Then create a new View file similar to the one below. |
| 3 | +To use WebForms Core, first copy the WebForms class file ("webforms.go") in this directory to "webforms" directory in your project. Then create a new View file ("main.go") similar to the one below. |
| 4 | +> Please make sure to replace "{your-project-name}" with project name in the import section. |
4 | 5 |
|
5 | 6 | ```go |
6 | 7 | package main |
7 | 8 |
|
8 | 9 | import ( |
9 | | - "fmt" |
10 | | - "net/http" |
11 | | - "strconv" |
| 10 | + "fmt" |
| 11 | + "{your-project-name}/webforms" |
| 12 | + "net/http" |
12 | 13 | ) |
13 | 14 |
|
14 | 15 | func main() { |
15 | | - http.HandleFunc("/", handleForm) |
16 | | - http.ListenAndServe(":8080", nil) |
| 16 | + http.Handle("/script/", http.StripPrefix("/script/", http.FileServer(http.Dir("script")))) |
| 17 | + http.HandleFunc("/", handleForm) |
| 18 | + http.ListenAndServe(":8080", nil) |
17 | 19 | } |
18 | 20 |
|
19 | 21 | func handleForm(w http.ResponseWriter, r *http.Request) { |
20 | | - if r.Method == http.MethodPost { |
21 | | - name := r.FormValue("txt_Name") |
22 | | - backgroundColor := r.FormValue("txt_BackgroundColor") |
23 | | - fontSize, err := strconv.Atoi(r.FormValue("txt_FontSize")) |
24 | | - if err != nil { |
25 | | - fontSize = 16 |
26 | | - } |
| 22 | + if r.Method == http.MethodPost { |
| 23 | + name := r.FormValue("txt_Name") |
| 24 | + backgroundColor := r.FormValue("txt_BackgroundColor") |
| 25 | + fontSize := r.FormValue("txt_FontSize") |
27 | 26 |
|
28 | | - form := new(WebForms) |
| 27 | + form := new(webforms.WebForms) |
| 28 | + ip := &webforms.InputPlace{} |
29 | 29 |
|
30 | | - form.setFontSize(InputPlace.tag("form"), fontSize) |
31 | | - form.setBackgroundColor(InputPlace.tag("form"), backgroundColor) |
32 | | - form.setDisabled(InputPlace.name("btn_SetBodyValue"), true) |
| 30 | + form.SetFontSize(ip.Tag("form"), fontSize+"px") |
| 31 | + form.SetBackgroundColor(ip.Tag("form"), backgroundColor) |
| 32 | + form.SetDisabled(ip.Name("btn_SetBodyValue"), true) |
33 | 33 |
|
34 | | - form.addTag(InputPlace.tag("form"), "h3") |
35 | | - form.setText(InputPlace.tag("h3"), "Welcome "+name+"!") |
| 34 | + form.AddTag(ip.Tag("form"), "h3", "p") |
| 35 | + form.SetText(ip.Tag("h3"), "Welcome "+name+"!") |
36 | 36 |
|
37 | | - fmt.Fprint(w, form.response()) |
38 | | - return |
39 | | - } |
| 37 | + fmt.Fprint(w, form.Response()) |
| 38 | + return |
| 39 | + } |
40 | 40 |
|
41 | | - fmt.Fprint(w, `<!DOCTYPE html> |
| 41 | + fmt.Fprint(w, `<!DOCTYPE html> |
42 | 42 | <html> |
43 | 43 | <head> |
44 | 44 | <title>Using WebForms Core</title> |
@@ -71,4 +71,4 @@ As you can see, the WebFormsJS script has been added in the header section of th |
71 | 71 |
|
72 | 72 | The latest version of the WebFormsJS script is available through the link below. |
73 | 73 |
|
74 | | -https://github.com/elanatframework/Web_forms/blob/elanat_framework/web-forms.js |
| 74 | +https://github.com/elanatframework/Web_forms/blob/elanat_framework/web-forms.js |
0 commit comments