Form with file type file for multiupload

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
leonardorocha
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Fri Mar 28, 2014 7:29 pm

Form with file type file for multiupload

Post by leonardorocha » Tue Dec 11, 2018 6:21 pm

Dear, I am creating a form and it contains a file type field for multiupload.

Look how the code is to load the variables and write to the database:

This is the field: <input type="file" id="arquivo" name="jform[][]" multiple accept=".pdf"/>

Code: Select all

// SAVE FUNCTION
    private function salvarArquivos($arquivos,$id) {
        $db = JFactory::getDbo();
        foreach ($arquivos as $arquivo) {
            $arquivoData = file_get_contents($arquivo[0]['tmp_name']);
            $arquivoSave = new stdClass();
            $arquivoSave->location_id = $id;
            $arquivoSave->name = $arquivo[0]['name'];
            $arquivoSave->mime = $arquivo[0]['type'];
            $arquivoSave->size = $arquivo[0]['size'];
            $arquivoSave->data = $arquivoData;
            $arquivoSave->created = date('Y-m-d H:i:s');
            $a = $db->insertObject( '#__mymaplocations_location_arquivos', $arquivoSave, 'id' );
        }
    }
        // SAVE ARRAY OF FILES
        //$up = $data['upload'];
        $data = JFactory::getApplication()->input->post->get('jform', array(), 'array');
        $arquivos = JFactory::getApplication()->input->files->get('jform', null, 'files');
        $id =  SELF::salvarInstituicao($data);
        SELF::salvarArquivos($arquivos,$id);
I am not able to write this data to the database.

I use the same logic to write a checkbox type field and to be all right, see below:

Code: Select all

<input type="checkbox" id="poder" name="jform[poder][]" value="1" > <label style="font-size: 17px;">Poder Executivo (exceto empresas públicas e sociedades de economia mista)</label> <br>
                            <input type="checkbox" id="poder" name="jform[poder][]" value="2" > <label style="font-size: 17px;">Poder Legislativo (exceto corte de contas)</label> <br>
                            <input type="checkbox" id="poder" name="jform[poder][]" value="3" > <label style="font-size: 17px;">Poder Judiciário</label> <br>
                            <input type="checkbox" id="poder" name="jform[poder][]" value="4" > <label style="font-size: 17px;">Tribunal de Contas</label> <br>

    // FUNCTION TO SAVE:
    private function salvarEsfera($esferas,$id) {
        $db = JFactory::getDbo();
        foreach ($esferas as $esfera) {
            $esferaSave = new stdClass();
            $esferaSave->location_id = $id;
            $esferaSave->esfera = $esfera;
            $esferaSave->created = date('Y-m-d H:i:s');
            $e = $db->insertObject( '#__mymaplocations_location_esfera', $esferaSave, 'id' );
        }
    }
        $esferas = $data['esfera'];
        SELF::salvarEsfera($esferas, $id)
Last edited by toivo on Tue Dec 11, 2018 7:12 pm, edited 1 time in total.
Reason: mod note: moved to 3.x Coding, changed subject from CAPS to normal case - please read the forum rules from https://forum.joomla.org/viewtopic.php?f=8&t=65

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44036
Joined: Sat Apr 05, 2008 9:58 pm

Re: Form with file type file for multiupload

Post by Webdongle » Tue Dec 11, 2018 8:16 pm

Are you creating the form as a Component or a module ... or are you creating it as a 3rd party extension?
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

leonardorocha
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Fri Mar 28, 2014 7:29 pm

Re: Form with file type file for multiupload

Post by leonardorocha » Tue Dec 11, 2018 8:42 pm

I am creating with a third party component, because the component does not meet 100% what I need. For this form I have 3 fields that write to different tables that are 2 checkboxes and one to upload. To get the ID I gave a extends main control of the component. The checkbox type fields are recording perfectly, however the upload field is not. Can you see any problems with the code? Sorry for the translation, because I'm using google translator.

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44036
Joined: Sat Apr 05, 2008 9:58 pm

Re: Form with file type file for multiupload

Post by Webdongle » Tue Dec 11, 2018 8:58 pm

Chronoforms has it's own predifined upload field http://www.chronoengine.com/faqs/74-chr ... r-web-form
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

leonardorocha
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Fri Mar 28, 2014 7:29 pm

Re: Form with file type file for multiupload

Post by leonardorocha » Tue Dec 11, 2018 9:59 pm

Hello Webdongle, I could use any forms component. The problem is that I have already taken this project in progress and the form has to save the data in the table of a third party component and it is as I informed it, there are several data and 3 of them in different tables. I believe the Chronoforms component does not do this. Because third-party component resources will still be used, I need the data to be written to their tables. You see?

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 44036
Joined: Sat Apr 05, 2008 9:58 pm

Re: Form with file type file for multiupload

Post by Webdongle » Tue Dec 11, 2018 11:12 pm

And there was me thinking that when you designed a form with chronoform that you could define the table that the field wrote to. Well that is me out of suggestions.
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".


Locked

Return to “Joomla! 3.x Coding”