#!/usr/bin/env perl use Mojolicious::Lite -signatures; get '/' => sub ($c) { $c->render(template => 'index'); } => 'index'; post '/submit' => sub ($c) { $c->render_later; Mojo::IOLoop->timer(10 => sub { # simulate long process if ( $c->param('foo') =~ /foo/i ) { $c->render(json => { ok=>1, message=>"All good" }); } else { $c->render(json => { ok=>0, message=>"Bad foo value" }); } }); } => 'formsubmit'; app->start; __DATA__ @@ layouts/main.html.ep <%= title %> %= content @@ index.html.ep % layout 'main', title => 'Hello, World!';
%= form_for formsubmit => ( method=>'post', id=>'myform' ) => begin
%= label_for foo => 'Foo' %= text_field foo => ( placeholder=>"Foo", required=>'required' ) (must contain "foo")
%= label_for bar => 'Bar' %= text_field bar => ( placeholder=>"Bar" )
%= submit_button 'Login'
%= end