[dancer-users] Help with a POST
Richard Reina
gatorreina at gmail.com
Mon Aug 10 18:34:20 BST 2015
I went to this example:
http://perlmaven.com/building-a-blog-engine-using-perl-dancer and noticed
that he put a get sub then followed by a post sub for the same page. Tried
this and it worked and the form no longer puts the submited imput into the
url which is my objective for using post. I hope that's okay.
2015-08-10 9:21 GMT-05:00 Richard Reina <gatorreina at gmail.com>:
> Hi John,
>
> I couple questions about your sample above:
>
> 1) in the simple form what should I put for action=?
>
> Here is what I have so far:
>
> <form action="index.tt">
> Query:<br>
> <input type="text" name="query" value="Mickey">
> <br><br>
> <input type="submit" value="Submit">
> </form>
>
> 2) This is what I have for the sub _perform_search
> sub _perform_search(
>
> my $fake_search_results = 'Comcast loves net neutrality";
> return $fake_search_results;
>
> )
>
> Is this okay?
>
>
>
>
>
>
>
>
> 2015-08-07 15:15 GMT-05:00 John Stoffel <john at stoffel.org>:
>
>>
>> Andrew,
>>
>> I think you really need to back up and start from scratch
>> again. Unfortunately I've got family around and can't spend the time
>> to help directly, but what I would do is:
>>
>>
>> 1. start a new dancer project.
>>
>> 2. build a new template for the index page with a <form ....>
>> ... </form> in it with just a single text entry and a submit button.
>> Simple stuff. Make sure the text post has a name of 'query'.
>>
>> 3. You need two routes in your lib/Module.pm file:
>>
>> package Module;
>> use Dancer ':syntax';
>> use Dancer::Plugin::DBIC;
>>
>> our $VERSION = '0.1';
>>
>> get '/' => sub {
>> template 'index', {
>> title => "The Index",
>> };
>> };
>>
>> get '/search' => sub {
>> my $query = params->{query} || "";
>> my $regexp = $query;
>> $regexp =~ s/\?|\*/\.\*/g;
>> my $tobold = $query;
>> $tobold =~ s/\?|\*//g;
>>
>> my @results = ();
>> my $limit = 50;
>> if (length $query) {
>> @results = _perform_search($regexp,$limit);
>> }
>> }
>>
>>
>> And of course a subroutine called _perform_search() to do the actual
>> work.
>>
>>
>> Once you have that working, try using the POST method, and adding in
>> the:
>>
>> post '/search2' => sub {
>>
>> }
>>
>> routines. Then you *should* be able ot handle it.
>>
>> I'd also look more closely at the Dancer Advent calendar stuff as
>> well. The advantage of GET calls is that you can more easily wrap
>> them into a div and return results, etc.
>>
>> But honestly I'm an old dog also learning new tricks... :-)
>>
>> John
>> _______________________________________________
>> 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/20150810/ff3208f9/attachment.html>
More information about the dancer-users
mailing list