doc: add link to the documentation and the demo

This commit is contained in:
Simon Vieille 2025-07-30 14:06:09 +02:00
commit d154000625
Signed by: deblan
GPG key ID: 579388D585F70417

View file

@ -2,9 +2,7 @@
Creating and processing HTML forms is hard and repetitive. You need to deal with rendering HTML form fields, validating submitted data, mapping the form data into objects and a lot more. [`go-form`][go-form] includes a powerful form feature that provides all these features.
## Introduction
[`go-form`][go-form] is heavily influenced by [Symfony Form](https://symfony.com/doc/current/forms.html). It includes:
[`go-form`][go-form] is heavily influenced by [Symfony Form](https://symfony.com/doc/current/forms.html). It includes:
* A form builder based on fields declarations and independent of structs
* Validation based on constraints
@ -12,70 +10,11 @@ Creating and processing HTML forms is hard and repetitive. You need to deal with
* Data binding to populate a struct instance from a submitted form
* Form renderer with customizable themes
## Installation
## Documentation
```shell
go get gitnet.fr/deblan/go-form
```
## Quick Start
```go
package main
import (
"html/template"
"log"
"net/http"
"gitnet.fr/deblan/go-form/form"
"gitnet.fr/deblan/go-form/theme"
"gitnet.fr/deblan/go-form/validation"
)
func main() {
type Person struct {
Name string
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data := new(Person)
f := form.NewForm(
form.NewFieldText("Name").
WithOptions(
form.NewOption("label", "Your name"),
).
WithConstraints(
validation.NewNotBlank(),
),
form.NewSubmit("submit"),
).
End().
WithMethod(http.MethodPost).
WithAction("/")
f.Mount(data)
if r.Method == f.Method {
f.HandleRequest(r)
if f.IsSubmitted() && f.IsValid() {
f.Bind(data)
}
}
render := theme.NewRenderer(theme.Html5)
tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(`{{ form .Form }}`)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
tpl.Execute(w, map[string]any{
"Form": f,
})
})
log.Fatal(http.ListenAndServe(":1324", nil))
}
```
* [Officiel documentation][doc]
* [Demo][demo]
[go-form]: https://gitnet.fr/deblan/go-form
[demo]: https://gitnet.fr/deblan/go-form-demo
[doc]: https://deblan.gitnet.page/go-form/