Exemple #1
0
// LoginForm returns a gform model for Login.
func (f *Form) LoginForm() gforms.ModelForm {
	var attrs = map[string]string{
		"class": "input-large",
	}
	return gforms.DefineModelForm(Login{}, gforms.NewFields(
		gforms.NewTextField(
			"email",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
				gforms.EmailValidator(f.tr.T(msgEmail)),
			},
			gforms.BaseTextWidget("email", attrs),
		),
		gforms.NewTextField(
			"password",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
				gforms.MinLengthValidator(6, f.tr.T(msgMinLength, 6)),
			},
			gforms.PasswordInputWidget(attrs),
		),
	))
}
Exemple #2
0
// RegisterForm implements gforms.ModelForm interface for Registration form.
func (f *Form) RegisterForm() gforms.ModelForm {
	var birtdateAttrs = map[string]string{
		"id":    "birthdate",
		"class": "input-large",
	}
	var inputAttrs = map[string]string{
		"class": "input-large",
	}
	return gforms.DefineModelForm(Register{}, gforms.NewFields(
		gforms.NewTextField(
			"first_name",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
			},
			gforms.TextInputWidget(inputAttrs),
		),
		gforms.NewTextField(
			"last_name",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
			},
			gforms.TextInputWidget(inputAttrs),
		),
		gforms.NewTextField(
			"middle_name",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
			},
			gforms.TextInputWidget(inputAttrs),
		),
		gforms.NewTextField(
			"email",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
				gforms.EmailValidator(f.tr.T(msgEmail)),
			},
			gforms.BaseTextWidget("email", inputAttrs),
		),
		gforms.NewTextField(
			"password",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
				gforms.MinLengthValidator(6, f.tr.T(msgMinLength, 6)),
			},
			gforms.PasswordInputWidget(inputAttrs),
		),
		gforms.NewTextField(
			"confirm_password",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
				gforms.MinLengthValidator(6, f.tr.T(msgMinLength, 6)),
				EqualValidator{To: "password", Message: f.tr.T(msgEqual)},
			},
			gforms.PasswordInputWidget(inputAttrs),
		),
		gforms.NewTextField(
			"gender",
			gforms.Validators{
				gforms.Required(f.tr.T(msgRequired)),
			},
			gforms.SelectWidget(
				inputAttrs,
				func() gforms.SelectOptions {
					return gforms.StringSelectOptions([][]string{
						{"Select...", "", "true", "false"},
						{"Male", "0", "false", "false"},
						{"Female", "1", "false", "false"},
						{"Zombie", "2", "false", "true"},
					})
				},
			),
		),

		gforms.NewDateTimeField(
			"birth_date",
			settings.App.BirthDateFormat,
			gforms.Validators{
				BirthDateValidator{Limit: settings.App.MinimumAge, Message: f.tr.T(msgAge, settings.App.MinimumAge)},
				gforms.Required(f.tr.T(msgRequired)),
			},
			gforms.BaseTextWidget("text", birtdateAttrs),
		),
	))
}