Code to generate. It's easier to use Wizard, but
here's the "old fashioned" way.
class SimpleWizard extends StatefulSnippet {
val fromWhence = S.referer openOr "/"
var dispatch: DispatchIt = {case _ => xhtml => pageOne}
var name = ""
var quest = ""
var color = ""
def pageOne = {
def validate() {
this.registerThisSnippet()
if (name.length < 2) S.error(S.?("Name too short"))
else dispatch = {case _ => xhtml => pageTwo}
}
TemplateFinder.findAnyTemplate(List("templating", "pageOne")).map(html =>
bind("wizard", html, "name" -> text(name, s => name = s), "submit" -> submit(S.?("Next"), validate))) openOr NodeSeq.Empty
}
def pageTwo = {
def validate() {
this.registerThisSnippet()
if (quest.length < 2) S.error(S.?("Quest too short"))
else dispatch = {case _ => xhtml => pageThree}
}
TemplateFinder.findAnyTemplate(List("templating", "pageTwo")).map(html =>
bind("wizard", html, "quest" -> text(quest, s => quest = s), "submit" -> submit(S.?("Next"), validate))) openOr NodeSeq.Empty
}
def pageThree = {
def validate() {
this.registerThisSnippet()
if (!List("red", "yellow", "blue").contains(color.toLowerCase)) S.error(S.?("Color not red, yellow or blue"))
else {
S.notice("You, "+name+" on the quest "+quest+" may cross the bridge of sorrows")
S.redirectTo(fromWhence)
}
}
TemplateFinder.findAnyTemplate(List("templating", "pageThree")).map(html =>
bind("wizard", html, "color" -> text(color, s => color = s), "submit" -> submit(S.?("Finish"), validate))) openOr NodeSeq.Empty
}
}