{
    "content": [
        {
            "type": "text",
            "text": "# CGI::FormBuilder::Template::HTML (perldoc)\n\n## NAME\n\nCGI::FormBuilder::Template::HTML - FormBuilder interface to HTML::Template\n\n## SYNOPSIS\n\nmy $form = CGI::FormBuilder->new(\nfields   => \\@fields,\ntemplate => 'form.tmpl',\n);\n\n## DESCRIPTION\n\nThis engine adapts FormBuilder to use \"HTML::Template\". \"HTML::Template\" is the default template\noption and is activated one of two ways. Either:\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **TEMPLATES**\n- **SEE ALSO**\n- **REVISION**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "CGI::FormBuilder::Template::HTML",
        "section": "",
        "mode": "perldoc",
        "summary": "CGI::FormBuilder::Template::HTML - FormBuilder interface to HTML::Template",
        "synopsis": "my $form = CGI::FormBuilder->new(\nfields   => \\@fields,\ntemplate => 'form.tmpl',\n);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 31,
                "subsections": []
            },
            {
                "name": "TEMPLATES",
                "lines": 194,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "REVISION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "CGI::FormBuilder::Template::HTML - FormBuilder interface to HTML::Template\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "my $form = CGI::FormBuilder->new(\nfields   => \\@fields,\ntemplate => 'form.tmpl',\n);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This engine adapts FormBuilder to use \"HTML::Template\". \"HTML::Template\" is the default template\noption and is activated one of two ways. Either:\n\nmy $form = CGI::FormBuilder->new(\nfields => \\@fields,\ntemplate => 'form.tmpl',\n);\n\nOr, you can specify any options which \"HTML::Template->new\" accepts by using a hashref:\n\nmy $form = CGI::FormBuilder->new(\nfields => \\@fields,\ntemplate => {\ntype => 'HTML',\nfilename => 'form.tmpl',\nsharedcache => 1,\nloopcontextvars => 1\n}\n);\n\nThe following methods are provided (usually only used internally):\n\nengine\nReturns a reference to the \"HTML::Template\" object\n\nprepare\nReturns a hash of all the fields ready to be rendered.\n\nrender\nUses the prepared hash and expands the template, returning a string of HTML.\n",
                "subsections": []
            },
            "TEMPLATES": {
                "content": "In your template, each of the form fields will correspond directly to a \"<tmplvar>\" of the same\nname prefixed with \"field-\" in the template. So, if you defined a field called \"email\", then you\nwould setup a variable called \"<tmplvar field-email>\" in your template.\n\nIn addition, there are a couple special fields:\n\n<tmplvar js-head>     -  JavaScript to stick in <head>\n<tmplvar form-title>  -  The <title> of the HTML form\n<tmplvar form-start>  -  Opening <form> tag and internal fields\n<tmplvar form-submit> -  The submit button(s)\n<tmplvar form-reset>  -  The reset button\n<tmplvar form-end>    -  Just the closing </form> tag\n\nLet's look at an example \"form.tmpl\" template we could use:\n\n<html>\n<head>\n<title>User Information</title>\n<tmplvar js-head><!-- this holds the JavaScript code -->\n</head>\n<tmplvar form-start><!-- this holds the initial form tag -->\n<h3>User Information</h3>\nPlease fill out the following information:\n<!-- each of these tmplvar's corresponds to a field -->\n<p>Your full name: <tmplvar field-name>\n<p>Your email address: <tmplvar field-email>\n<p>Choose a password: <tmplvar field-password>\n<p>Please confirm it: <tmplvar field-confirmpassword>\n<p>Your home zipcode: <tmplvar field-zipcode>\n<p>\n<tmplvar form-submit><!-- this holds the form submit button -->\n</form><!-- can also use \"tmplvar form-end\", same thing -->\n\nAs you see, you get a \"<tmplvar>\" for each for field you define.\n\nHowever, you may want even more control. That is, maybe you want to specify every nitty-gritty\ndetail of your input fields, and just want this module to take care of the statefulness of the\nvalues. This is no problem, since this module also provides several other \"<tmplvar>\" tags as\nwell:\n\n<tmplvar value-[field]>   - The value of a given field\n<tmplvar label-[field]>   - The human-readable label\n<tmplvar comment-[field]> - Any optional comment\n<tmplvar error-[field]>   - Error text if validation fails\n<tmplvar required-[field]> - See if the field is required\n\nThis means you could say something like this in your template:\n\n<tmplvar label-email>:\n<input type=\"text\" name=\"email\" value=\"<tmplvar value-email>\">\n<font size=\"-1\"><i><tmplvar error-email></i></font>\n\nAnd FormBuilder would take care of the value stickiness for you, while you have control over the\nspecifics of the \"<input>\" tag. A sample expansion may create HTML like the following:\n\nEmail:\n<input type=\"text\" name=\"email\" value=\"nate@wiger.org\">\n<font size=\"-1\"><i>You must enter a valid value</i></font>\n\nNote, though, that this will only get the *first* value in the case of a multi-value parameter\n(for example, a multi-select list). To remedy this, if there are multiple values you will also\nget a \"<tmplvar>\" prefixed with \"loop-\". So, if you had:\n\nmyapp.cgi?color=gray&color=red&color=blue\n\nThis would give the \"color\" field three values. To create a select list, you would do this in\nyour template:\n\n<select name=\"color\" multiple>\n<tmplloop loop-color>\n<option value=\"<tmplvar value>\"><tmplvar label></option>\n</tmplloop>\n</select>\n\nWith \"<tmplloop>\" tags, each iteration gives you several variables:\n\nInside <tmplloop>, this...  Gives you this\n---------------------------  -------------------------------\n<tmplvar value>             value of that option\n<tmplvar label>             label for that option\n<tmplvar checked>           if selected, the word \"checked\"\n<tmplvar selected>          if selected, the word \"selected\"\n\nPlease note that \"<tmplvar value>\" gives you one of the *options*, not the values. Why? Well,\nif you think about it you'll realize that select lists and radio groups are fundamentally\ndifferent from input boxes in a number of ways. Whereas in input tags you can just have an empty\nvalue, with lists you need to iterate through each option and then decide if it's selected or\nnot.\n\nWhen you need precise control in a template this is all exposed to you; normally FormBuilder\ndoes all this magic for you. If you don't need exact control over your lists, simply use the\n\"<tmplvar field-[name]>\" tag and this will all be done automatically, which I strongly\nrecommend.\n\nBut, let's assume you need exact control over your lists. Here's an example select list\ntemplate:\n\n<select name=\"color\" multiple>\n<tmplloop loop-color>\n<option value=\"<tmplvar value>\" <tmplvar selected>><tmplvar label>\n</tmplloop>\n</select>\n\nThen, your Perl code would fiddle the field as follows:\n\n$form->field(\nname => 'color', nameopts => 1,\noptions => [qw(red green blue yellow black white gray)]\n);\n\nAssuming query string as shown above, the template would then be expanded to something like\nthis:\n\n<select name=\"color\" multiple>\n<option value=\"red\" selected>Red\n<option value=\"green\" >Green\n<option value=\"blue\" selected>Blue\n<option value=\"yellow\" >Yellow\n<option value=\"black\" >Black\n<option value=\"white\" >White\n<option value=\"gray\" selected>Gray\n</select>\n\nNotice that the \"<tmplvar selected>\" tag is expanded to the word \"selected\" when a given option\nis present as a value as well (i.e., via the CGI query). The \"<tmplvar value>\" tag expands to\neach option in turn, and \"<tmplvar label>\" is expanded to the label for that value. In this\ncase, since \"nameopts\" was specified to \"field()\", the labels are automatically generated from\nthe options.\n\nLet's look at one last example. Here we want a radio group that allows a person to remove\nthemself from a mailing list. Here's our template:\n\nDo you want to be on our mailing list?\n<p><table>\n<tmplloop loop-mailopt>\n<td bgcolor=\"silver\">\n<input type=\"radio\" name=\"mailopt\" value=\"<tmplvar value>\">\n</td>\n<td bgcolor=\"white\"><tmplvar label></td>\n</tmplloop>\n</table>\n\nThen, we would twiddle our \"mailopt\" field via \"field()\":\n\n$form->field(\nname => 'mailopt',\noptions => [\n[ 1 => 'Yes, please keep me on it!' ],\n[ 0 => 'No, remove me immediately.' ]\n]\n);\n\nWhen the template is rendered, the result would be something like this:\n\nDo you want to be on our mailing list?\n<p><table>\n\n<td bgcolor=\"silver\">\n<input type=\"radio\" name=\"mailopt\" value=\"1\">\n</td>\n<td bgcolor=\"white\">Yes, please keep me on it!</td>\n\n<td bgcolor=\"silver\">\n<input type=\"radio\" name=\"mailopt\" value=\"0\">\n</td>\n<td bgcolor=\"white\">No, remove me immediately</td>\n\n</table>\n\nWhen the form was then sumbmitted, you would access the values just like any other field:\n\nif ($form->field('mailopt')) {\n# is 1, so add them\n} else {\n# is 0, remove them\n}\n\nFinally, you can also loop through each of the fields using the top-level \"fields\" loop in your\ntemplate. This allows you to reuse the same template even if your parameters change. The\nfollowing template code would loop through each field, creating a table row for each:\n\n<table>\n<tmplloop fields>\n<tr>\n<td class=\"small\"><tmplif required><b><tmplvar label></b><tmplelse><tmplvar label></tmplif></td>\n<td><tmplvar field></td>\n</tr>\n</tmplloop>\n</table>\n\nEach loop will have a \"label\", \"field\", \"value\", etc, just like above.\n\nFor more information on templates, see HTML::Template.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "CGI::FormBuilder, CGI::FormBuilder::Template, HTML::Template\n",
                "subsections": []
            },
            "REVISION": {
                "content": "$Id: HTML.pm 100 2007-03-02 18:13:13Z nwiger $\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Copyright (c) Nate Wiger <http://nateware.com>. All Rights Reserved.\n\nThis module is free software; you may copy this under the terms of the GNU General Public\nLicense, or the Artistic License, copies of which should have accompanied your Perl kit.\n",
                "subsections": []
            }
        }
    }
}