html - Websharper, Sitelets and Forms -
html - Websharper, Sitelets and Forms -
i've been trying create form using websharper collect user input. far i've identified 3 actions site:
type myaction = | [<compiledname "">] index | [<method "post">] getuser of username : string | stats of username: string using sitelet.infer i've managed implement basic ui, have no thought how refer content of input box (usernameinput):
sitelet.infer <| function | index -> content.pagecontent <| fun ctx -> allow usernameinput= input [text ""] { page.default title = "welcome!" body = [ div [ form [ usernameinput-< [name "username" ] input [value "request"] -< [type "submit" ] ] -< [ attr.action (ctx.link (* getuser usernameinput.content *) ); method "post" ] ] ] } | getuser username -> content.redirect <| stats username | stats username -> content.pagecontent <| fun ctx -> { page.default body = [text ("stats " + username)] } i noticed usernameinput doesn't have field "value" or , guess either needs casting or i'm doing wrong.
i prefer not utilize javascript in code (is possible mix html.server , html.client elements in sitelet @ ?).
form post info not passed via url, cannot pass ctx.link. automatically passed via request body, format similar query arguments (for illustration in case, username=myusername). not parsed sitelet.infer, although add together in future. can utilize action without arguments , extract info request:
type myaction = | [<method "post">] getuser | // ... sitelet.infer <| function | getuser -> content.customcontentasync <| fun ctx -> match ctx.request.post.["username"] | none -> content.notfound | username -> content.redirect <| stats username |> content.toresponseasync ctx | // ... html forms f# websharper
Comments
Post a Comment