Created
August 22, 2008 16:58
-
-
Save archaelus/6816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(mochiweb_signup_form_controller). | |
-export([serve_form/2]). | |
serve_form('GET', Req) -> | |
{ok, Form} = form:render(signup_form()), | |
Req:ok("text/html", Form); | |
serve_form('POST', Req) -> | |
Post = Req:parse_post(), | |
case form:valid_post(signup_form(), Post) of | |
{valid, Fields} -> | |
NewAcct = [{name, proplists:get_value("txtusername",Fields)}, | |
{pass, proplists:get_value("txtpassword",Fields)}, | |
{addr, proplists:get_value("txtemailaddress",Fields)}], | |
Req:ok("text/html", io_lib:format("New account: ~p", [NewAcct])); | |
{invalid, Result, Fields} -> | |
{ok, Form} = form:render_with_fields(signup_form(), Fields), | |
Req:ok("text/html", Form) | |
end. | |
signup_form() -> | |
form:create("Account details", | |
"", % URL to this form (POST) | |
[form:text("User Name:", [string, not_empty, {length, [3,30]}, | |
{not_predicate, fun vhreg_account:exists/1}]), | |
form:text("Email Address:", [not_empty, email_address]), | |
form:password("Password:", "txtpassword", | |
[password, not_empty, {length, [8, infinity]}]), | |
form:password("Re-enter Password:", "txtpasswordc", | |
[]), | |
form:submit("Register") | |
], | |
[{"passwords", [{duplication, ["txtpassword", "txtpasswordc"]}]}] | |
). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment