package form

import (
	"errors"
	"net/http"
	"strings"
)

type SettingsForm struct {
	Homepage string
	About    string
	Picture  string
	Email    string
}

func (f *SettingsForm) Validate() error {
	if strings.Contains(f.About, "<script") {
		return errors.New("script tag is forbidden")
	}
	return nil
}

func NewSettingsForm(r *http.Request) *SettingsForm {
	return &SettingsForm{
		Homepage: r.FormValue("homepage"),
		About:    r.FormValue("about"),
		Picture:  r.FormValue("picture"),
		Email:    r.FormValue("email"),
	}
}
