| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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),
- Kind: "text",
- }
- }
- /* Generate new password field */
- func NewPasswordField(name string) *FormField {
- return &FormField{
- Name: name,
- Kind: "password",
- }
- }
- /* Generate a new checkbox field */
- func NewCheckboxField(name string, checked bool) *FormField {
- return &FormField{
- Name: name,
- Checked: checked,
- Kind: "checkbox",
- }
- }
- /* 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),
- Kind: "hidden",
- Sticky: true,
- Validators: ValidatorsList{
- ValidCSRF(r),
- },
- }
- }
- /* Generate a new hidden text field */
- func NewHiddenField(name string, value *string) *FormField {
- return &FormField{
- Name: name,
- Value: strFromPtr(value),
- Kind: "hidden",
- }
- }
|