How to get form parameters and placeholders is covered in Mojolicious::Guides::Tutorial. I see you've commented out Mojo::SQLite, but I personally like these Mojo-style DB adapters.

Form parameters don't normally get put in the URL in the way you seem to be hoping. One possible solution would be JavaScript, but here is a solution without it: the HTML form gets submitted to a handler at /search, which then just redirects to the corresponding URL. Note I'm generating the form via Mojolicious::Plugin::TagHelpers.

#!/usr/bin/env perl use Mojolicious::Lite; use Mojo::SQLite; helper sqlite => sub { state $sql = Mojo::SQLite->new('sqlite:mydb.db') }; # disable template cache when running under morbo app->renderer->cache->max_keys(0) if app->mode eq 'development'; app->sqlite->migrations->from_string(<<'END_MIGR')->migrate; -- 1 up CREATE TABLE contacts ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, department TEXT ); INSERT INTO contacts (name,department) VALUES ('John Doe','Perl'); -- 1 down DROP TABLE IF EXISTS contacts; END_MIGR get '/' => sub { my $c = shift; $c->render('main'); } => 'index'; post '/search' => sub { my $c = shift; $c->redirect_to( $c->url_for('name_query', query => $c->param('name') ) ); } => 'search'; get '/name/:query' => sub { my $c = shift; $c->stash( rows => $c->sqlite->db->select( 'contacts', ['id','name','department'], { name => $c->stash('query') } )->arrays ); $c->render('main'); } => 'name_query'; app->start; __DATA__ @@ main.html.ep <!DOCTYPE html> <html> <head><title>Hello Mojo!</title></head> <body> <div> %= form_for search => ( method => 'post' ) => begin %= label_for name => 'Name' %= text_field 'name', required=>'required'; %= submit_button 'Query' %= end </div> % if ( my $rows = stash 'rows' ) { % if (@$rows) { <div><table border="1"> <tr> <th>id</th> <th>name</th> <th>department</th> </tr> % foreach my $row (@$rows) { <tr> % foreach my $text (@$row) { <td><%= $text %></td> % } </tr> % } </table></div> % } else { <div><b>No records found!</b></div> % } % } </body> </html>

In reply to Re: Mojo database routing by haukex
in thread Mojo database routing by rajaman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.