[dancer-users] Help with a POST

Richard Reina gatorreina at gmail.com
Fri Aug 7 18:23:22 BST 2015


Here is what I get from curl.

curl http://0.0.0.0:3000/user
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Error 404</title>
<link rel="stylesheet" href="/css/error.css" />
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Error 404</h1>
<div id="content">
<h2>Page Not Found</h2><p>Sorry, this is the void.</p>
</div>
<div id="footer">
Powered by <a href="http://perldancer.org/">Dancer</a>.
</div>
</body>
</html>



2015-08-07 12:12 GMT-05:00 Andrew Solomon <andrew at geekuni.com>:

> That looks very much like you're only managing to make GET calls. I
> suggest you use curl at the command-line at the outset, then you can
> struggle with getting your browser to obey:)
>
> Andrew
>
> On Fri, Aug 7, 2015 at 5:58 PM, Richard Reina <gatorreina at gmail.com>
> wrote:
>
>> Sorry this is my dancer console output:
>>
>> >> Dancer 1.3140 server 24745 listening on http://0.0.0.0:3000
>> >> Dancer::Plugin::FormValidator (1.131620)
>> == Entering the development dance floor ...
>> [24745]  core @0.000165> request: GET /user from 127.0.0.1 in
>> /usr/local/share/perl/5.14.2/Dancer/Handler.pm l. 58
>> [24745]  core @0.000569> [hit #1]Trying to match 'GET /user' against
>> /^\/$/ (generated from '/') in /usr/local/share/perl/5.14.2/Dancer/Route.pm
>> l. 85
>> [24745]  core @0.000757> [hit #1]Trying to match 'GET /user' against
>> /^\/player$/ (generated from '/player') in
>> /usr/local/share/perl/5.14.2/Dancer/Route.pm l. 85
>> [24745]  core @0.000932> [hit #1]Trying to match 'GET /user' against
>> /^\/sponsor$/ (generated from '/sponsor') in
>> /usr/local/share/perl/5.14.2/Dancer/Route.pm l. 85
>> [24745]  core @0.001113> [hit #1]Trying to match 'GET /user' against
>> /^\/$/ (generated from '/') in /usr/local/share/perl/5.14.2/Dancer/Route.pm
>> l. 85
>> [24745]  core @0.001282> [hit #1]Trying to match 'GET /user' against
>> /^\/player$/ (generated from '/player') in
>> /usr/local/share/perl/5.14.2/Dancer/Route.pm l. 85
>> [24745]  core @0.001452> [hit #1]Trying to match 'GET /user' against
>> /^\/sponsor$/ (generated from '/sponsor') in
>> /usr/local/share/perl/5.14.2/Dancer/Route.pm l. 85
>> [24745]  core @0.001956> [hit #1]response: 304 in
>> /usr/local/share/perl/5.14.2/Dancer/Handler.pm l. 181
>> [24745]  core @0.000174> request: GET /css/error.css from 127.0.0.1 in
>> /usr/local/share/perl/5.14.2/Dancer/Handler.pm l. 58
>> [24745]  core @0.000710> [hit #2]response: 304 in
>> /usr/local/share/perl/5.14.2/Dancer/Handler.pm l. 181
>>
>>
>>
>> 2015-08-07 11:58 GMT-05:00 Richard Reina <gatorreina at gmail.com>:
>>
>>> 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
>>>>>
>>>>
>>>>
>>>
>>
>> _______________________________________________
>> dancer-users mailing list
>> dancer-users at dancer.pm
>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>>
>>
>
>
> --
> Andrew Solomon
>
> Mentor at Geekuni http://geekuni.com/
> http://www.linkedin.com/in/asolomon
>
> _______________________________________________
> 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/560a0174/attachment-0001.html>


More information about the dancer-users mailing list