使用参数提交表单后,将重定向提升到新页面

And*_*yuk 5 lift

如何将表单提交的结果传递给我重定向到的页面?

例如,假设我有以下逻辑:

Search Page -> validate

if errors - show Search Page again with errors   <--- this part works
else - redirect to New Page(passing search params)  <-- no params passed
Run Code Online (Sandbox Code Playgroud)

我的表单处理看起来像这样:

  def process() = {
    if (nameame== "Joe") {
      S.error("Joe not allowed!")
    }
    val dateRegex="(\\d\\d/\\d\\d/\\d\\d\\d\\d|\\w*)";

    if (!birthdate.matches(dateRegex)) {
      S.error("birthdate", "Invalid date. Please enter date in the form dd/mm/yyyy.")
    }

    S.errors match {
        case Nil =>S.notice("Name: " + name); S.redirectTo("search-results")
        case _ =>S.redirectTo(S.uri)
    }
  }
Run Code Online (Sandbox Code Playgroud)

正如你所看到的 - 我的搜索结果没有获得"名字"或"生日"参数.当我进行S.redirectTo调用时,如何从表单中传递参数?

如果我能以某种方式澄清这个问题,请告诉我.

Daa*_*der 1

您可以将参数存储在 SessionVar 中,并从 search_results 片段或任何需要的地方访问它们。请参阅http://stable.simply.liftweb.net/#toc-Section-4.4

否则你总是可以这样做:

S.redirectTo("search-results?param1=value1") //Not very clean though
Run Code Online (Sandbox Code Playgroud)