| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package forms
- import "net/http"
- /* strFromPtr converts string pointer to a string */
- func strFromPtr(str *string) (s string) {
- if str != nil {
- s = *str
- }
- return
- }
- /* Generate new CharField field with type text */
- func NewCharField(Name string, Value *string) *FormField {
- return &FormField{
- Name: Name,
- Value: strFromPtr(Value),
- Class: "form-control",
- Type: "text",
- }
- }
- /* Generate a new hidden text field */
- func NewHiddenField(Name string, Value *string) *FormField {
- return &FormField{
- Name: Name,
- Value: strFromPtr(Value),
- Class: "form-control",
- Type: "hidden",
- }
- }
- /* Generate a new CSRF field */
- func NewCsrfField(w http.ResponseWriter, r *http.Request, secure bool) *FormField {
- return &FormField{
- Name: csrfFieldName,
- Value: csrfToken(w, r, secure),
- Class: "form-control",
- Type: "hidden",
- Sticky: true,
- Validators: ValidatorsList{
- ValidCSRF(r),
- },
- }
- }
- /* Generate new CharField field with type password */
- func NewPasswordField(Name string) *FormField {
- field := NewCharField(Name, nil).SetType("password")
- return field
- }
|