Exemplo n.º 1
0
func (r *reCaptcha) FieldAddOns(ctx *app.Context, field *form.Field) []*form.AddOn {
	if field.Name == "Recaptcha" {
		style := &html.Node{
			Tag:      "style",
			Attrs:    html.Attrs{"type": "text/css"},
			Children: html.Text(css),
		}
		theme := &html.Node{
			Tag:      "script",
			Attrs:    html.Attrs{"type": "text/javascript"},
			Children: html.Text(fmt.Sprintf("var RecaptchaOptions = {theme : '%s'};", r.theme)),
		}
		src := fmt.Sprintf("//www.google.com/recaptcha/api/challenge?k=%s", r.publicKey)
		if r.msg != "" {
			src += fmt.Sprintf("&error=%s", r.msg)
		}
		script := &html.Node{
			Tag:   "script",
			Attrs: html.Attrs{"type": "text/javascript", "src": src},
		}
		return []*form.AddOn{
			&form.AddOn{
				Node: html.Div(style, theme, script),
			},
		}
	}
	return nil
}
Exemplo n.º 2
0
func (r *FormRenderer) BeginField(w io.Writer, field *form.Field) error {
	attrs := html.Attrs{"class": "form-group"}
	if field.Err() != nil {
		attrs["class"] += " has-error"
	}
	div := html.Div()
	div.Attrs = attrs
	div.Open = true
	_, err := div.WriteTo(w)
	if err == nil && field.Type == form.CHECKBOX {
		cb := html.Div()
		cb.Attrs = html.Attrs{"class": "checkbox"}
		cb.Open = true
		_, err = cb.WriteTo(w)
	}
	return err
}
Exemplo n.º 3
0
func (r *FormRenderer) BeginLabel(w io.Writer, field *form.Field, label string, pos int) error {
	var err error
	if field.Type == form.CHECKBOX || field.Type == form.RADIO {
		if c := r.inlineLabelClass(); c != "" {
			div := html.Div()
			div.Attrs = html.Attrs{"class": c}
			div.Open = true
			_, err = div.WriteTo(w)
		}
	}
	if err == nil && field.Type == form.RADIO && pos >= 0 {
		div := html.Div()
		div.Attrs = html.Attrs{"class": "radio"}
		div.Open = true
		_, err = div.WriteTo(w)
	}
	return err
}
Exemplo n.º 4
0
func (r *FormRenderer) BeginInput(w io.Writer, field *form.Field, placeholder string, pos int) error {
	var err error
	if field.HasAddOns() && pos == -1 {
		div := html.Div()
		div.Attrs = html.Attrs{"class": "input-group"}
		div.Open = true
		_, err = div.WriteTo(w)
	}
	return err
}
Exemplo n.º 5
0
func (r *FormRenderer) EndLabel(w io.Writer, field *form.Field, pos int) error {
	var err error
	if field.Type == form.RADIO && pos >= 0 {
		_, err = io.WriteString(w, "</div>")
	}
	if err == nil {
		if field.Type != form.CHECKBOX && field.Type != form.RADIO {
			if c := r.inputDivClass(); c != "" {
				div := html.Div()
				div.Attrs = html.Attrs{"class": c}
				div.Open = true
				_, err = div.WriteTo(w)
			}
		}
	}
	return err
}