[dancer-users] Help with a POST
James Baer
jamesfbaer at gmail.com
Fri Aug 7 19:03:27 BST 2015
You still need to have a GET route to display the form:
get '/user' => sub {
template 'user';
}
Then when you submit the form it will go to your POST route handler.
On Fri, Aug 7, 2015 at 1:59 PM, Richard Reina <gatorreina at gmail.com> wrote:
> I can't get the page to appear in the browser so I can't press the Go
> button.
>
> I get:
>
> Error 404
> Page Not Found
>
> Sorry, this is the void.
> Powered by Dancer <http://perldancer.org/>.
>
>
> This is user.tt
>
> <!DOCTYPE html>
> <html>
> <body>
>
> <h1>Get in the game.</h1>
>
> <form action="user" method="post">
> First name:<br>
> <input type="text" name="firstname">
> <br>
> Last name:<br>
> <input type="text" name="lastname">
> <br>
> Email Address:<br>
> <input type="text" name="email">
> <br>
> User Password:<br>
> <input type="password" name="psw">
> <br>
> User Confirm Password:<br>
> <input type="password" name="psw2">
> <br>
> Terms & Conditions
> <input type="checkbox" name="terms"> I agree with terms and conditions.<br>
> <br>
> <input type="submit" value="Go" />
> </form>
>
> <p>Note that the form itself is not visible.</p>
>
> <p>Also note that the default width of a text field is 20 characters.</p>
>
> </body>
> </html>
>
>
>
> 2015-08-07 12:38 GMT-05:00 Kadir Beyazlı <kadirbeyazli at gmail.com>:
>
>> Richard,
>>
>> Would you please copy template 'user' here?
>> If everything is OK, when you click on "Go" button, POST requests will be
>> performed
>>
>>
>>
>> On Fri, Aug 7, 2015 at 8:30 PM, Richard Reina <gatorreina at gmail.com>
>> wrote:
>>
>>> Yes and just did and tried again to make sure.
>>>
>>> 2015-08-07 12:16 GMT-05:00 Kadir Beyazlı <kadirbeyazli at gmail.com>:
>>>
>>>> Hi Richard,
>>>>
>>>> Did you restart server after you changed GET with POST at form
>>>> definition?
>>>>
>>>>
>>>> On Fri, Aug 7, 2015 at 7: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
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> *Kadir BeyazlıComputer Engineer*
>>>> *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
>>>>
>>>> _______________________________________________
>>>> 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
>>>
>>>
>>
>>
>> --
>>
>> *Kadir BeyazlıComputer Engineer*
>> *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
>>
>> _______________________________________________
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150807/67f5de74/attachment-0001.html>
More information about the dancer-users
mailing list