Adding file select/upload to setup form

Discussion in 'Integration' started by richard_fullbrook984, Dec 26, 2015.

  1. ENTS

    ENTS aMember Pro Customer

    Joined:
    Aug 13, 2015
    Messages:
    10
    I'm trying to add either a file select or upload (doesn't matter which) to have the admin upload a json file with some values in it. These values shouldn't really be plain text in the form, so I'd rather avoid a series of text boxes.

    I've tried using the 'upload' element described here and here, but it only produces the error 'prefix is not defined in element Am_Form_Element_Upload'.

    This is the code I'm using (stripped down to save space). I'm using a module as the code provides a fair amount of functionality beyond a simple plugin.
    PHP:
    <?php
    class Bootstrap_Test extends Am_Module {
      public function 
    onSetupForms(Am_Event_SetupForms $event) {
        
    $form = new Am_Form_Setup('test');
        
    $form->setTitle("Test Module");

        
    $fs $form->addFieldSet()->setLabel('Settings');
        
    $fs->addUpload('json-file'); // Error: 'prefix is not defined in element Am_Form_Element_Upload'

        
    $form->addFieldsPrefix('test.');
        
    $event->addForm($form);
      }
    }
    ?>
    This is the stacktrace for the error:
    Code:
    Exception Am_Exception_InternalError
    Am_Form_Element_Upload->__construct [ library/pear/HTML/QuickForm2/Factory.php : 173 ]
    HTML_QuickForm2_Factory::createElement [ library/pear/HTML/QuickForm2/Container.php : 260 ]
    HTML_QuickForm2_Container->addElement [ application/test/Bootstrap.php : 8 ]
    Bootstrap_Test->onSetupForms
    call_user_func [ library/Am/Event.php : 784 ]
    Am_Event->call [ library/Am/Event.php : 807 ]
    Am_Event->handle [ library/Am/Hook.php : 202 ]
    Am_Hook->call [ application/default/controllers/AdminSetupController.php : 156 ]
    AdminSetupController->initSetupForms [ application/default/controllers/AdminSetupController.php : 67 ]
    AdminSetupController->displayAction [ library/Am/Controller.php : 139 ]
    Am_Controller->_runAction [ library/Am/Controller.php : 116 ]
    Am_Controller->dispatch [ library/Zend/Controller/Dispatcher/Standard.php : 308 ]
    Zend_Controller_Dispatcher_Standard->dispatch [ library/Zend/Controller/Front.php : 954 ]
    Zend_Controller_Front->dispatch [ library/Am/App.php : 2019 ]
    Am_App->run [ index.php : 92 ]
    Any help is appreciated. I'd rather stick to the file upload if possible, however a file select would also work for this case. I'd prefer to stay away from a series of text boxes if possible.
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You need to define prefix eg.:
    PHP:
    $fs->addUpload('json-file', array(), array('prefix' => 'test'));
    I recommend you to use id of your module as file prefix.

Share This Page