Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

repopulate HTML form from database

by Anonymous Monk
on Oct 04, 2017 at 18:42 UTC ( [id://1200668]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have written a Perl program which creates radio, checkboxes and text input to analyze a photo and save (to Oracle) characteristics of the photograph.

Now I am trying to do the reverse; read the data base and repopulate the various containers such that the original selections are recreated. I am stuck on how I can move a piece of data into the correct container (by which I mean the original dropdown box/option.

Replies are listed 'Best First'.
Re: repopulate HTML form from database
by pryrt (Abbot) on Oct 04, 2017 at 20:25 UTC

    Use the data stored in your structure (variable, hash element, or element deep in your complex data structure): For radio groups or menus, use the data to determine whether the CHECKED should be set for a radio input (<input type=radio ... CHECKED='checked'>) or whether the SELECTED should be set on the given menu option (<OPTION VALUE="..." SELECTED>) as you are generating the HTML (there should be a way in your templating engine to programmatically determine whether or not the CHECKED or SELECTED apply to the various elements of your form). For INPUT and TEXTAREA and the like, just pass the data from your structure into the VALUE or content of the HTML tag, as appropriate to the given HTML tag (<INPUT ... value="$variable"> or <TEXTAREA>$variable</TEXTAREA>, however your templating engine wants that formatted).

    (UPDATE: after "generating", added "the HTML", to clarify my sentence; also, give examples of the INPUT/TEXTAREA)

Re: repopulate HTML form from database
by 1nickt (Canon) on Oct 04, 2017 at 20:06 UTC

    Select the record from the DB, pass it to your template as a JSON-encoded data structure, use a Javascript framework like Angular to populate the form controls on the HTML page from the JSON data object.


    The way forward always starts with a minimal test.
Re: repopulate HTML form from database
by Anonymous Monk on Oct 04, 2017 at 18:51 UTC
      I cannot post any code. Suffice to say that I have all data from the table from the original analysis.
Re: repopulate HTML form from database
by poj (Abbot) on Oct 04, 2017 at 19:28 UTC
    I have written a Perl program..

    Ok, can you post it ?

    poj
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1200668]
Approved by sweetblood
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 10:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found