docdurdee has asked for the wisdom of the Perl Monks concerning the following question:
EDIT: I think I figured it out the first step. I got rid of the post command, and added a new get with a route placeholder:#!/usr/bin/env perl use Mojolicious::Lite; use Path::Tiny; plugin 'TagHelpers'; get '/' => sub{ my $c = shift; my $path = path("/Foo/Bar/Baz"); $c->stash(filepath => $path, files => [$path->children(qr/\.txt/)] + ); $c->render('index'); }; post '/' => sub{ my $c = shift; my $file = $c->param('id'); print $file; # print to console $c->render(text => $file); }; app->start; __DATA__ @@ index.html.ep % layout 'default'; % title $filepath ; <h1>Let's test the files in <%= $filepath %>!</h1> <table border="1"> <tr> <th>File</th> <th>Action</th> </tr> % foreach my $file (@$files) { <tr><td><%= $file %></td> <td> %= form_for '/' => (method => 'POST') => begin %= submit_button 'validate', id => $file % end </td> </tr> % } </table> @@ layouts/default.html.ep <!DOCTYPE html> <html> <head><title><%= title %></title></head> <body><%= content %></body> </html>
Then I mixed a little JQuery into the button:get '/validate/*filename' => sub{ my $c = shift; print $c->param('filename'),"\n\n\n\n"; # print to console $c->render('index'); };
And that sends back the file name. Very cool. Thanks in advance if you point out a better way or provide any other tips.<input type='button' value='validate' onclick = "$.get('/validate/<%= +$file %>');">
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mojolicious to and from buttons
by Anonymous Monk on Aug 29, 2016 at 22:47 UTC | |
by Anonymous Monk on Aug 29, 2016 at 22:50 UTC |