Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
700 views
in Plugins by
recategorized by

I would like to place a dialog where admin can choose a path for a file and upload it.
It could be simple textbox, but maybe there is a better way ?

 

EDIT:

I created a form in my plugin in function admin_form()  in a static field (there is a whole html form in a single static field) :

Files in backup folder:
 - why it doesn't work ?

FORM IN OUTERN FILE - works.

 

1 Answer

+3 votes
by
selected by
 
Best answer

<INPUT TYPE="FILE" NAME="file">

and the form needs to have:

METHOD=POST ENCTYPE="multipart/form-data"

if you want to actually send the file to the server.

edit:

to put this in $form:

$form = array(
    'style' => 'tall', // or 'wide'
    'title' => 'My File Form', // <h2>My File Form</h2>
    'tags' => 'NAME="myform" METHOD=POST ENCTYPE="multipart/form-data"',
    'fields' => array(
        array(
            'type' => 'static',
            'value' => '<INPUT TYPE="FILE" NAME="file">',
        ),
    )
);

 

EDIT2: You need a layer, i think, not just a plugin module.  Put this in a custom layer:

        function form($form)
        {
            if ($this->template=='admin' && $this->request == 'admin/plugins' && strpos(@$form['title'],'mytitle')) {
                $form['tags'] = 'METHOD=POST ENCTYPE="multipart/form-data" ACTION="mypage" '.@$form['tags'];
            }
            qa_html_theme_base::form($form);
        }

 

by
However it fires the main form which is not multipart/form-data type - so I am unable to upload a file.
The main plugin form (in admin section) is returned by admin_form().
Do you have idea how to create a form outside the main form ?
by
I don't understand... each plugin has its own form, afaics.  What you do is create a layer with a form() function like this:

        function form($form)
        {
            if ($this->template=='admin' && $this->request == 'admin/plugins' && strpos($form['title'],'mytitle')) {
                $form['tags'] = 'METHOD=POST ENCTYPE="multipart/form-data" action="mypage" '.$form['tags'];
            }
            qa_html_theme_base::form($form);
        }

It seems to work for me...
by
edited by
Thank you. It works!
by
Great :) Actually, I already did edit my answer to include this; you can also just use @$form['title'] - the ampersand suppresses errors.
...