[Ur] Handling the POST request
Artyom Shalkhakov
artyom.shalkhakov at gmail.com
Tue May 9 23:42:31 EDT 2017
2017-05-10 9:34 GMT+06:00 Jeevjyot Chhabda <jeevsingh at mail.fresnostate.edu>:
> Greetings,
>
> I was wondering if there is way to handle the bogus values in the POST
> request or of the wrong type? Would bogus values will result in fatal error?
> How we catch them and show the appropriate error in Ur/Web, more sort of
> validation.
>
While I don't know the details, you could probably start off at this
demo (pasted straight from the Ur/Web's online demo):
fun handler r = return <xml><body>
<table>
<tr> <th>A:</th> <td>{[r.A]}</td> </tr>
<tr> <th>B:</th> <td>{[r.B]}</td> </tr>
<tr> <th>C:</th> <td>{[r.C]}</td> </tr>
</table>
</body></xml>
fun main () = return <xml><body>
<form>
<table>
<tr> <th>A:</th> <td><textbox{#A}/></td> </tr>
<tr> <th>B:</th> <td><textbox{#B}/></td> </tr>
<tr> <th>C:</th> <td><checkbox{#C}/></td> </tr>
<tr> <th/> <td><submit action={handler}/></td> </tr>
</table>
</form>
</body></xml>
In [handler], the type of [r] is [{ A : string, B : string, C : bool
}]. You could put some checks prior to returning the HTML result,
e.g.:
fun handler r =
case (@read read_int r.A) of
None => return <xml><body>
<p>Unable to parse A!</p>
</body></xml>
| Some => ... (* same as before *)
I'm sorry, I have not tested the above code, but the idea should be
clear enough.
>
>
> thanks,
>
> Jeevjyot
>
>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
--
Cheers,
Artyom Shalkhakov
More information about the Ur
mailing list