Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.9k 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
reshown by
Okay, it's quite obvious, but how to place it in a plugin form. There is a method admin_form() that returns an array. Now I have textbox and I would like to convert it into select file dialog.
'fields' => array(
            array(
                'label' => 'File path:',
                'type' => 'text',
                'value' => 'mytext',
                'tags' => 'NAME="myplugin_mytextbox"',
            ),
by
There is no "file" type in Q2A, I think; use "static" type - see edited answer.
by
edited by
I cannot execute form when I click on the button. (See my edited question).
- Upload button doesn't redirect to other url.
Do you have idea why ?
When I fire my form in an external file, it works.
Maybe the problem is, I have a form in a field of the main plugin form ?
...is't one of the last steps of my batabase backup plugin.
by
the form redirects to whatever is in the action="" tag.  You'll have to edit the form() function, and edit its tags, I think.
by
I think the point is you can't put a form inside another form... can you?
by
Okay,
I had to put a tag to my input-submit-button in my inner form: name="my_submit_button" AND above in admin_form() handle the inner form by
if (qa_clicked('my_submit_button')) {    }
Inner form redirects to the same page. Works great.
Thank you for (re)directing me in the right way !
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.
...