useMojolicious::Lite;get'/'=>sub{my$c=shift;# Check if parameters have been submittedmy$validation=$c->validation;return$c->renderunless$validation->has_data;# Validate parameters ("pass_again" depends on "pass")$validation->required('user')->uc->size(1,20)->like(qr/^[E-T]+$/);$validation->required('pass_again')->lc->equal_to('pass')if$validation->optional('pass')->lc->size(7,500)->is_valid;# Render confirmation if validation was successful$c->render('thanks')unless$validation->has_error;}=>'index';app->start;__DATA__@@index.html.ep<!DOCTYPEhtml><html><head><style>label.field-with-error{color:#dd7e5e }input.field-with-error{background-color:#fd9e7e }password.field-with-error{background-color:#fd9e7e }</style></head><body>%=form_forindex=>begin%=label_foruser=>'Username (required, 1-20 characters, only e-t)'<br>%=text_field'user'%=submit_button<br>%=label_forpass=>'Password (optional, 7-500 characters)'<br>%=password_field'pass'<br>%=label_forpass_again=>'Password again (equal to the value above)'<br>%=password_field'pass_again'%end</body></html>@@thanks.html.ep<!DOCTYPEhtml><html><body>Thankyou<%=validation->param('user')%>.</body></html>
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.