I'm new to Racket though I've managed so far to play around with servlets and make few things work. What I would like to do now is to validate a simple username/password POST request. I've had success in doing it so through the "web-server/formlets" module but the formlet-process
function is forcing me to name all inputs with the pattern: input_0
, input_1
, etc. which I find awkward and inconvenient for every single input element present in the form. I don't understand the reason(s) behind not allowing the user to override automatic naming of HTML inputs to be processed by a formlet:
(define (get-username/password request)
(define login-formlet
(formlet
(#%# ,{input-string . => . username}
,{input-string . => . password})
(values username password)))
(formlet-process login-formlet request))
The above function expects the POST request to contain the username in the input_0
key and the password in the input_1
key, so my HTML template is forced to name the "username" input as input_0
and the "password" as input_1
(otherwise formlet-process
will complain):
<html>
<head>
<title>Please login</title>
</head>
<body>
<form action="" method="post">
<label for="username">Username:</label>
<input type="text" name="input_0" required>
<label for="password">Password:</label>
<input type="password" name="input_1" required>
<button type="submit" value="Login">Login</button>
</form>
<div>
<p></p>
</div>
</body>
</html>
If there's a way to override automatic naming I couldn't find it (hope I didn't miss anything from the docs!):
https://docs.racket-lang.org/web-server/formlets.html
So I've decided to take a step back and try to do the processing by myself and landed at:
but the documentation itself discourages its use (without pointing out an alternative raw safe way to do so!) as it might be hard to get sanitized values from it. So here is my question: Is there a built-in way to properly and safely extract/process sanitized values from a POST request without requiring more than built-in or simple functions in Racket? I'm really interested in not depending on any 3rd party package or module but what Racket already provides.
Thanks in advance!