Gossamer Forum
Quote Reply
pre_install form
How do I use a form in a plugin's pre_install sub?

According to docs...
Quote:
The pre install function displays a message to the user before the plugin is installed. It should return a string containing HTML that will be displayed. You can output an HTML form with form fields asking the user any information you will need in the actual install.

I am trying to create a plugin install option that is the directory in which to install template.html files.

I am slowly making progress on the form, and having some difficulties as
the pre_install function does not allow me to use tags like I can in templates.
Furthermore, I don't understand how I then retrieve the form data once in the install sub.

Also, I do not know how to walk the hashref returned from Links::Tools::tpl_dir_select();
I am trying to create a dropdown menu of installed template sets.
This is the code I am working on. If anyone could shed some light this,
I would be greatful. I need to be able to use a while loop to index through
$template_set_loop, but I don't have <%loop template_set_loop%>.
Obviously I am confused.

Code:
sub pre_install {
# -----------------------------------------------------------------------------
# This function displays an HTML formatted message that will display any
# instructions/information to the user before they install the plugin.
#

my $Config = GT::Config->load("$CFG->{admin_root_path}/Links/Config/Data.pm");
my $theme = $Config->{'build_default_tpl'};
my $directory = 'luna';

# Links::Config::load_vars;
my $template_set_loop = Links::Tools::tpl_dir_select($theme, 'browser', '', 0);

my $popup = "<select name='templates'>";
#while ($template_set_loop) {
$popup.= "<option value=".$directory;
if($directory == $theme) {$popup .= " selected='selected'"; }
$popup .= ">".$directory."</option>";
#}
$popup.= "</select>";


my $inst_msg = qq~
$popup

<p>Choose a template set for this plugin's templates.<br>
If you install to the luna template set, the templates will be available to any set that inherits from luna.</p>

<form method="post" action="dummy_value">
<%Links::Tools::tpl_dir_select('luna, 'browser')%>
<select name='dburl'>
<%loop template_set_loop%>
<option value="<%directory%>"<%if $directory eq $theme%> selected="selected"<%endif%>><%directory%></option>
<%endloop%>
</select>
</form>

~;

return $inst_msg;
}
This is basically scrap code, but it is all I have been able to muster up concidering the lack of <%foo%> tags.
The above <form> code doesn't really work at all, but it is what i had working in a template.

Thank you,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com

Last edited by:

rgbworld: May 15, 2006, 7:35 PM
Quote Reply
Re: [rgbworld] pre_install form In reply to
As you noticed, you can't use template code in what you return. All you can return is plain html.

tpl_dir_select was designed to be used in a template, so it returns a hashref with template_set_loop as the only key. So you need to do something like this:
Code:
require Links::Tools;
my $ret = Links::Tools::tpl_dir_select(undef, '(?:admin|browser)');

my $tplsel = qq|<select name="templates">|;
for (@{$ret->{template_set_loop}}) {
$tplsel .= qq|<option|;
$tplsel .= qq| selected="selected"| if $_->{dir_selected};
$tplsel .= qq|>$_->{directory}</option>|;
}
$tplsel = qq|</select>|;

And in the install function, you can just grab the value using $IN->param('templates');

Adrian
Quote Reply
Re: [brewt] pre_install form In reply to
Perfect of course.

That last line should be '.=', not '=':

$tplsel .= qq|</select>|;

Thank you,
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com