Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lift redirect to a new page after form submission with parameters

Tags:

lift

How can I pass results of a form submission to a page that I redirect to?

For example, lets say i have the following logic:

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

My form processing looks something like this:

  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)
    }
  }

As you can see - my search results is not getting a "name" or "birthdate" params. How can I pass the parameters from the form when I do a S.redirectTo call?

Let me know if I can clarify the question somehow.

like image 845
Andriy Drozdyuk Avatar asked Nov 13 '22 23:11

Andriy Drozdyuk


1 Answers

You can store the parameters in SessionVar's and access them from your search_results snippet or wherever you need them. See http://stable.simply.liftweb.net/#toc-Section-4.4.

Otherwise you could always do:

S.redirectTo("search-results?param1=value1") //Not very clean though
like image 150
DaafVader Avatar answered Dec 20 '22 08:12

DaafVader