Custom Installation Fields
If you need custom installation fields other than those included in the basic cPAddons install, those are available as well. For example, if you need a secondary contact email, you may need a custom field. If you need specific info for a proper installation, you can use the following additional keys for the
$meta_info hash ref:
install_fields
install_fields will build your install form to make sure the input you need exists. Here, you can add your extra fields for text, radio buttons, etc. This hashref is used to build the input fields. Here are some guidelines:
- Do not use addon, email, auser, apass, installdir, or action as your keys they are reserved and will be ignored.
- Each "type" below must use the value as-is (ie, if it's a hashref below, it always has to be a hashref; if it's a string it always has to be a string.
- The key is the name attribute of the form field. You can use them in your config and sql files with
[% input_NAME %] where "=NAME=" is the key.
- If multiple entries exist (ie, multiple select or checkbox) they will be
[% input_NAME %] [% input_NAME-0 %] [% input_NAME-1 %], etc.
- You are responsible for verifying the input is correct and doing any quoting or erroring out before the install function is run.
- If a module is being moderated and you die/quit/exit in your install function (ie, saying "invalid motto; please re-enter your motto"), then the moderation approval will need to be redone. So use caution! Or better yet, use
install_fields_hook =>
Here is a sample hashref that contains each type of field:
'install_fields' => {
'test_text' => {
'label' => 'Text',
'value' => 'text value',
'attr' => 'size="32"',
'type' => 'text',
},
'test_hidden' => {
'label' => 'Hidden',
'value' => 'Hidden value',
'attr' => 'attr="2"',
'type' => 'hidden',
},
'test_password' => {
'label' => 'Password',
'value' => 'password value',
'attr' => 'size="10"',
'type' => 'password'
},
'test_textarea' => {
'label' => 'Text Area',
'value' => 'textarea text',
'attr' => 'cols="51"',
'type' => 'textarea',
},
'test_select' => {
'label' => 'Select',
'value' => { foo => 'FOo', bar=> 'Bar' },
'attr' => '',
'type' => 'select',
'defvalue' => 'bar',
},
'test_radio' => {
'label' => 'Radio',
'value' => { 1=> 'One', 2=> 'Two', 3=>'Three'},
'attr' => '',
'type' => 'radio',
'defvalue' => '2',
},
'test_multi' => {
'label' => 'Multi',
'value' => {4=>'Four',5=>'Five',6=>'Siz',7=>'Seven'},
'attr' => 'size="2"',
'type' => 'multi',
'defvalue' => [5,7],
},
'test_checkbox' => {
'label' => 'Checkbox',
'value' => {8=>'Eight',9=>'Nine',10=>'Ten',11=>'Eleven'},
'attr' => '',
'type' => 'checkbox',
'defvalue' => [8,11],
},
},
install_fields_hook
You should always use
install_fields_hook when using
install_fields. The
install_fields_hook checks input from the form generated using
install_fields. It should be modified to make sure input is parsed properly and will not corrupt your configuration or MySQL files. Failure to properly evaluate and escape this input may result in a broken installation.
If you need to modify any input, you will need to modify
$obj->{'input_whatever'} since the object key is used as a config variable. Changing
$input_hr->{'whatever'} will have no effect on what gets put into the install.
'install_fields_hook' => sub {
my ($input_hr, $error_hr, $obj)= @_;
# escape single quotes so it doesn't break the
# single quoted value in the config file (= '[% install_foo %]';)
$obj->{'input_foo'} =~ s{'}{\\'}g;
# check $input_hr and if there are problems set the error like so:
print "Checking your laces...<br />\n";
${$error_hr} = "Your shoes are untied, try again"
if !_laces_are_tied_tight($input_hr->{'shoes'});
},