[dancer-users] Help with a POST

Richard Reina gatorreina at gmail.com
Fri Aug 7 17:58:23 BST 2015


This is my dancer console output.



2015-08-07 11:11 GMT-05:00 Richard Reina <gatorreina at gmail.com>:

> replacing the first few lines with:
>
> <html>
> <body>
>
> <h1>Get in the game.</h1>
>
> <form action="user" method="POST">
> First name:<br>
>
> I still get Error 404
>
> Interestingly enough when I modify this
> http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit to
> method="POST" it does not work either.
>
> 2015-08-07 10:54 GMT-05:00 John Stoffel <john at stoffel.org>:
>
>>
>> And I know there's a helper you can use to fill in the action so that
>> you don't have to update the URLs when you deploy it elsewhere.... but
>> I'm at work and not near my notes...
>>
>> Ah... here it is.  Just do:
>>
>> <form action="user">
>>
>> And I think you also want to remove the <!DOCTYPE html> as well, since
>> this template will get embedded into alayout which will take care of
>> all that stuff.
>>
>> John
>>
>>
>> Andrew> I think what you're after is something like this to tell the
>> browser you want to POST:
>> Andrew> <form action="http://localhost:3000/user" method="POST">
>>
>> Andrew> Does that do the trick?
>>
>> Andrew> A
>>
>> Andrew> On Fri, Aug 7, 2015 at 3:47 PM, Richard Reina <
>> gatorreina at gmail.com> wrote:
>>
>> Andrew>     Wait, Does this provide a clue to the error of my ways? This
>> is the template (user.tt) that I
>> Andrew>     am using for the form.
>>
>> Andrew>     <!DOCTYPE html>
>> Andrew>     <html>
>> Andrew>     <body>
>>
>> Andrew>     <h1>Get in the game.</h1>
>>
>> Andrew>     <form>
>> Andrew>     First name:<br>
>> Andrew>     <input type="text" name="firstname">
>> Andrew>     <br>
>> Andrew>     Last name:<br>
>> Andrew>     <input type="text" name="lastname">
>> Andrew>     <br>
>> Andrew>     Email Address:<br>
>> Andrew>     <input type="text" name="email">
>> Andrew>     <br>
>> Andrew>     User Password:<br>
>> Andrew>     <input type="password" name="psw">
>> Andrew>     <br>
>> Andrew>     User Confirm Password:<br>
>> Andrew>     <input type="password" name="psw2">
>> Andrew>     <br>
>> Andrew>     Terms & Conditions
>> Andrew>     <input type="checkbox" name="terms"> I agree with terms and
>> conditions.<br>
>> Andrew>     <br>
>> Andrew>     <input type="submit" value="Go" />
>> Andrew>     </form>
>>
>> Andrew>     <p>Note that the form itself is not visible.</p>
>>
>> Andrew>     <p>Also note that the default width of a text field is 20
>> characters.</p>
>>
>> Andrew>     </body>
>> Andrew>     </html>
>>
>> Andrew>     2015-08-07 9:36 GMT-05:00 John Stoffel <john at stoffel.org>:
>>
>> Andrew>         You need to build a web page with a FORM first, then
>> submit the data
>> Andrew>         that way to the /user URL, so it can get handled.
>>
>> Andrew>         Try using git to clone this repository and use that as a
>> base for your
>> Andrew>         playing around:
>>
>> Andrew>
>> https://github.com/agordon/dancer_bootstrap_fontawesome_template.git
>>
>> Andrew>         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
>> Andrew>         _______________________________________________
>> Andrew>         dancer-users mailing list
>> Andrew>         dancer-users at dancer.pm
>> Andrew>         http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>>
>> Andrew>     _______________________________________________
>> Andrew>     dancer-users mailing list
>> Andrew>     dancer-users at dancer.pm
>> Andrew>     http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>>
>> Andrew> --
>> Andrew> Andrew Solomon
>>
>> Andrew> Mentor at Geekuni http://geekuni.com/
>> Andrew> http://www.linkedin.com/in/asolomon
>>
>> Andrew> _______________________________________________
>> Andrew> dancer-users mailing list
>> Andrew> dancer-users at dancer.pm
>> Andrew> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>> _______________________________________________
>> dancer-users mailing list
>> dancer-users at dancer.pm
>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150807/39e7b8e4/attachment-0001.html>


More information about the dancer-users mailing list