[dancer-users] Help with a POST

John Stoffel john at stoffel.org
Fri Aug 7 15:36:00 BST 2015


You need to build a web page with a FORM first, then submit the data
that way to the /user URL, so it can get handled.  

Try using git to clone this repository and use that as a base for your
playing around:

https://github.com/agordon/dancer_bootstrap_fontawesome_template.git

I don't have any working examples handy right this second...

Richard> I am hoping someone can help me understand how to get this to
Richard> work as a POST instead of GET.  When I do sub below as 'get'
Richard> it works but when I replace 'get' with 'post' I get:

Richard> --2015-08-06 13:52:05--  http://0.0.0.0:3000/user
Richard> Connecting to 0.0.0.0:3000... connected.
Richard> HTTP request sent, awaiting response... 404 Not Found
Richard> 2015-08-06 13:52:05 ERROR 404: Not Found.

Richard> package MyApp;
Richard> use Dancer ':syntax';
Richard> use Dancer::Plugin::FormValidator;

Richard> our $VERSION = '0.1';

Richard> post '/user' => sub {
    
Richard>    my $input_hash = {  
       
Richard>        FName => param('firstname'),  
Richard>        LName => param('lastname'),
Richard>        Email => param('email'),
Richard>        Terms => param('terms'),

Richard>    }; 

Richard>    my $number_of_defined_values = scalar grep { defined } values %{$input_hash};
Richard>    $number_of_defined_values = $number_of_defined_values + 0;

Richard>    if ($number_of_defined_values > 1) {

Richard>          my $error = form_validator_error( 'profile_user', $input_hash );
       
Richard>         if ( ! $error ) {
Richard>             #the user provided complete and validates data it's cool to proceed

Richard>         } else {

Richard>              my %hash = %$error;
Richard>              foreach my $k (keys %hash) {
Richard>                  return "$k: $hash{$k}\n";
             
Richard>              }
          
Richard>         }
Richard>    }

Richard>    template 'user';

Richard> ##########################################################
Richard> }; ### end of sub user ###################################

Richard> true;

Richard> Thanks in advance for any help.

Richard> _______________________________________________
Richard> dancer-users mailing list
Richard> dancer-users at dancer.pm
Richard> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users


More information about the dancer-users mailing list