web applications - How to get parameters in an HTML page passed from a snippet with Lift framework -


i want develop lift web app, i've index page has in here body:

<div id="main" class="lift:surround?with=default&at=content">   <div> app </div>    <div>     <form method="post" class="lift:dumbform">        <table>             <tr><td> email:</td> <td><input name="email" type="text"></td></tr>             <tr><td> password:</td> <td><input name="pwd" type="password"></td></tr>             <tr><td> name:</td> <td><input name="name" type="text"></td></tr>             <tr><td><input type="submit" value="sign in"></td> <td><input type="reset" value="reset"></td></tr>         </table>     </form>   </div>  </div> 

with corresponding snippet (file "dumbform.scala"):

package code package snippet  import net.liftweb._ import http._ import scala.xml.nodeseq  /**  * snippet grabs query parameters  * form post , processes them  */ object dumbform {   def render(in: nodeseq): nodeseq = {       // use scala for-comprehension evaluate each parameter     {       r <- s.request if r.post_? // make sure it's post       name <- s.param("name") // name field     } {       s.notice("nom: "+name)       s.redirectto("/hello")     }      // pass through html if don't post ,     // parameters     in   } } 

i want pass attribute "name" snippet view, html page, ("hello.html") , display name.

but don't know how pass "name" parameter snippet view (hello.html), , how parameter in view?!

for moment, hello.html has:

<body> <p> hello ... (you must display name!)</p> </body> 

to looking do, point form directly @ ever hello.html mounted. assuming hello in same path.

dumbform.html

<div id="main" class="lift:surround?with=default&at=content">   <div> app </div>    <div>     <form method="post" action="hello">        <table>             <tr><td> email:</td> <td><input name="email" type="text"></td></tr>             <tr><td> password:</td> <td><input name="pwd" type="password"></td></tr>             <tr><td> name:</td> <td><input name="name" type="text"></td></tr>             <tr><td><input type="submit" value="sign in"></td> <td><input type="reset" value="reset"></td></tr>         </table>     </form>   </div>  </div> 

hello.html

<div data-lift="showhellosnippet">   <p>hello <span name="paramname"></span></p> </div> 

snippet

class showhellosnippet {   def render = {     "@paramname" #> s.param("name")   } } 

the more lift way thought, use lift's shtml form elements:

dumbform.html

<div id="main" class="lift:surround?with=default&at=content">   <div> app </div>    <div>     <form method="post" data-lift="formhandlersnippet">        <table>             <tr><td> email:</td> <td><input name="email" type="text"></td></tr>             <tr><td> password:</td> <td><input name="pwd" type="password"></td></tr>             <tr><td> name:</td> <td><input name="name" type="text"></td></tr>             <tr><td><input id="submitbutton" type="submit" value="sign in"></td> <td><input type="reset" value="reset"></td></tr>         </table>     </form>   </div>  </div> 

snippet

class myformresponse(     var email:string="",      var password:string="",      var name:string ="")  class formhandlersnippet {    def render = {      val responseform = new myformresponse()      "@email" #> shtml.text("", (valuesupplied) => {         responseform.email = valuesupplied      }) &      "@pwd" #> shtml.password("", (valuesupplied) => {         responseform.password = valuesupplied      }) &      "@name" #> shtml.text("", (valuesupplied) => {         responseform.name = valuesupplied      }) &      "#submitbutton" #> shtml.submit("sign in", () => {         s.redirectto("/hello", () => showhellosnippet.myvals(full(responseform)))      })   } } 

hello.html

<div data-lift="showhellosnippet">   <p>hello <span name="paramname"></span></p> </div> 

snippet

object showhellosnippet {   object myvals extends requestvar[box[myformresponse]](empty) }  class showhellosnippet {   def render = "*" #> {     showhellosnippet.myvals.get.map { r =>       "@paramname" #> r.name     }   } } 

this have form set values on object, stateful redirect sets values in showhellosnippet use after page has been redirected. alternate both, use ajax display values on same page.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -