in reply to Re^2: Perl: info from database into a form(HTML)
in thread Perl: info from database into a form(HTML)

This is really where I'm stuck at and have no clue how to proceed, how do I display the retrieved info from the database to the user in the form fields so it can be modified without the info being submitted to the second database first.
  • Comment on Re^3: Perl: info from database into a form(HTML)

Replies are listed 'Best First'.
Re^4: Perl: info from database into a form(HTML)
by Corion (Patriarch) on Jul 30, 2016 at 06:10 UTC

    You will need two functions in your Perl program:

    1. Display a row to the user for editing
    2. Save a row to the new database after editing

    So, I would introduce an URL parameter, say, action, which is either display (or empty) for the display action and save for the save action. Output something like the following HTML in the display action:

    <input type="hidden" name="action" value="save">

    You will likely also want to offer the user an option to reset their input:

    <a href="?action=display;row=$current_row_identifier">Reset changes</a +>

    You decide which part of your program to execute based on the action value:

    my $action = param('action') || 'display'; if( $action eq 'save' ) { ... } elsif( $action eq 'display ) { ... } else { # Weird error };

    Personally, I would look into Mojolicious or Dancer for doing the scaffolding of the web part of the application, but as they both are frameworks, you will have to learn some stuff not tightly related to creating the HTML and talking to the database. It is also quite feasible to do all you need with just Perl and print statements for the HTML generation.