Forums

Multisave on DB uploaded data

livingwebstudio 04 Dec, 2015
I'm tryng to save on two tables my data form:
Array
(
    [chronoform] => Articolo
    [event] => submit
    [titolo] => 556
    [autori] => 556
    [contenuti_extra] => 
    [caratteri] => 11
    [invia] => Invia
    [giudizio_text] => 
    [giudizio_inglese] => 
    [giudizio_grafica] => 1
    [giudizio_plagiarism] => 1
    [check_text] => 0
    [check_inglese] => 0
    [check_grafica] => 0
    [check_plagiarism] => 0
    [english_user_id] => 
    [graphic_user_id] => 
    [plagiarism_user_id] => 
    [articolo] => 556_Errori_dmb.docx
    [foto] => Array
        (
            [0] => 556_dmb_contatti.png
            [1] => 556_ftgoogle122014.png
        )

)
Array
(
    [articolo] => Array
        (
            [name] => 556_Errori_dmb.docx
            [original_name] => Errori_dmb.docx
            [path] => articoli/201512041100_645_556/556_Errori_dmb.docx
            [size] => 13536
            [link] => articoli/201512041100_645_556/556_Errori_dmb.docx
        )

    [foto] => Array
        (
            [0] => Array
                (
                    [name] => 556_dmb_contatti.png
                    [original_name] => dmb_contatti.png
                    [path] => articoli/201512041100_645_556/556_dmb_contatti.png
                    [size] => 36176
                    [link] => articoli/201512041100_645_556/556_dmb_contatti.png
                )

            [1] => Array
                (
                    [name] => 556_ftgoogle122014.png
                    [original_name] => ftgoogle122014.png
                    [path] => articoli/201512041100_645_556/556_ftgoogle122014.png
                    [size] => 41002
                    [link] => articoli/201512041100_645_556/556_ftgoogle122014.png
                )

        )

)

I'm tryng to save [foto] Array on second table
I have two DB save action on my setup: one (article_photo) I wish it contains each row for uploaded files.
I set db save like this:
save under model ID: YES
multisave: YES
model ID: foto

the debug is this..
Array
(
    [2] => Array
        (
            [Files Upload] => Array
                (
                    [0] => Upload routine started for file upload by : articolo
                    [1] => articoli/201512041122_645_ffg/ffg_Errori_dmb.docx has been uploaded successfully.
                    [2] => Upload routine started for file upload by : foto
                    [3] => articoli/201512041122_645_ffg/ffg_dmb_contatti.png has been uploaded successfully.
                    [4] => Upload routine started for file upload by : foto
                    [5] => articoli/201512041122_645_ffg/ffg_ftgoogle122014.png has been uploaded successfully.
                )

        )

    [25] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                        )

                )

        )

    [17] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `jm3_chronoengine_chronoforms_datatable_articolo` (`titolo`, `autori`, `contenuti_extra`, `caratteri`, `invia`, `giudizio_text`, `giudizio_inglese`, `giudizio_grafica`, `giudizio_plagiarism`, `check_text`, `check_inglese`, `check_grafica`, `check_plagiarism`, `english_user_id`, `graphic_user_id`, `plagiarism_user_id`, `articolo`, `foto`, `articolo_url`, `file0_url`, `file1_url`, `user_id`, `uniq_id`, `created`) values ('ffg', 'ffg', '', '332', 'Invia', '', '', '1', '1', '0', '0', '0', '0', '', '', '', 'ffg_Errori_dmb.docx', 'Array', 'articoli/201512041122_645_ffg/ffg_Errori_dmb.docx', 'articoli/201512041122_645_ffg/ffg_dmb_contatti.png', 'articoli/201512041122_645_ffg/ffg_ftgoogle122014.png', '645', 'd2b07b8f69d309a798c8e8fd840cff3d1f21af87', '2015-12-04 11:22:45');
                        )

                )

        )

)
GreyHead 04 Dec, 2015
Hi livingwebstudio,

I'm not clear exactly what you need to do here?

To be saved, the data needs to be in the $form->data array. That is the first part of the Debugger output down to [foto].

[foto] is an array so is not saving correctly, it needs to be converted into a string - the Handle Arrays action will do that.

The second part of the Debugger output is in the $form->files array - if you want to safe part of that it need to be copied over into the $form->data array with the correct names. (You've seen how to do that in the other forum thread.)

Bob
livingwebstudio 04 Dec, 2015
hi Bob,
i have two tables
ARTICOLO
FOTO
in FOTO table I want to save as many lines as files I'm uloading (FOTO array).. i hope it's clear now.. sorry for my bad BAD english!๐Ÿ™‚
GreyHead 04 Dec, 2015
Hi livingwebstudio,

You need the DB Save to the Articolo table to come first in the ON Submit event. After that the Record ID of the new record will be available in the $form->data array. I don't see that in the Debugger. Typically it will be $form->data['id'] or $form->data['cf_id']

You can then create the data for your file records using a Custom Code action like this:
<?php
$foto = array();
foreach ( $form->files['foto'] as $k => $f ) {
  $foto[$k]['record_id'] = $form->data['cf_id']; // the Articolo record id
  $foto[$k]['name'] = $f['name'];
  $foto[$k]['original_name'] = $f['original_name'];
  $foto[$k]['path'] = $f['path'];
  $foto[$k]['size'] = $f['size'];
  $foto[$k]['link'] = $f['link'];
}
$form->data['foto'] = $foto;
?>
The run your second DB Save with the Multi setting.

NB You may not need to save all these items, and your column named may be different

Bob

[[>> later : removed ); to fix a typo <<]]
livingwebstudio 04 Dec, 2015
it doesn't work๐Ÿ˜Ÿ
Array
(
    [chronoform] => Articolo
    [event] => submit
    [titolo] => 1414
    [autori] => 1414
    [contenuti_extra] => 12
    [caratteri] => 22
    [invia] => Invia
    [giudizio_text] => 
    [giudizio_inglese] => 
    [giudizio_grafica] => 1
    [giudizio_plagiarism] => 1
    [check_text] => 0
    [check_inglese] => 0
    [check_grafica] => 0
    [check_plagiarism] => 0
    [english_user_id] => 
    [graphic_user_id] => 
    [plagiarism_user_id] => 
    [email_utente] => giorgio.magno85+1@gmail.com
    [articolo] => 1414_Errori_dmb.docx
    [foto] => Array
        (
            [0] => 1414_dmb_contatti.png
            [1] => 1414_ftgoogle122014.png
        )

    [articolo_url] => articoli/201512041612_655_1414/1414_Errori_dmb.docx
    [foto0_url] => articoli/201512041612_655_1414/1414_dmb_contatti.png
    [foto1_url] => articoli/201512041612_655_1414/1414_ftgoogle122014.png
    [foto2_url] => 
    [foto3_url] => 
    [foto4_url] => 
    [foto5_url] => 
    [foto6_url] => 
    [foto7_url] => 
    [foto8_url] => 
    [foto9_url] => 
    [foto0_original_name] => dmb_contatti.png
    [foto1_original_name] => ftgoogle122014.png
    [foto2_original_name] => 
    [foto3_original_name] => 
    [foto4_original_name] => 
    [foto5_original_name] => 
    [foto6_original_name] => 
    [foto7_original_name] => 
    [foto8_original_name] => 
    [foto9_original_name] => 
    [paypal_amount] => 0.66
    [paypal_int] => 0
    [paypal_dec] => 66
    [id] => 0
)
Array
(
    [articolo] => Array
        (
            [name] => 1414_Errori_dmb.docx
            [original_name] => Errori_dmb.docx
            [path] => articoli/201512041612_655_1414/1414_Errori_dmb.docx
            [size] => 13536
            [link] => articoli/201512041612_655_1414/1414_Errori_dmb.docx
        )

    [foto] => Array
        (
            [0] => Array
                (
                    [name] => 1414_dmb_contatti.png
                    [original_name] => dmb_contatti.png
                    [path] => articoli/201512041612_655_1414/1414_dmb_contatti.png
                    [size] => 36176
                    [link] => articoli/201512041612_655_1414/1414_dmb_contatti.png
                )

            [1] => Array
                (
                    [name] => 1414_ftgoogle122014.png
                    [original_name] => ftgoogle122014.png
                    [path] => articoli/201512041612_655_1414/1414_ftgoogle122014.png
                    [size] => 41002
                    [link] => articoli/201512041612_655_1414/1414_ftgoogle122014.png
                )

        )

)


Array
(
    [2] => Array
        (
            [Files Upload] => Array
                (
                    [0] => Upload routine started for file upload by : articolo
                    [1] => articoli/201512041612_655_1414/1414_Errori_dmb.docx has been uploaded successfully.
                    [2] => Upload routine started for file upload by : foto
                    [3] => articoli/201512041612_655_1414/1414_dmb_contatti.png has been uploaded successfully.
                    [4] => Upload routine started for file upload by : foto
                    [5] => articoli/201512041612_655_1414/1414_ftgoogle122014.png has been uploaded successfully.
                )

        )

    [17] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `jm3_chronoengine_chronoforms_datatable_articolo` (`titolo`, `autori`, `contenuti_extra`, `caratteri`, `invia`, `giudizio_text`, `giudizio_inglese`, `giudizio_grafica`, `giudizio_plagiarism`, `check_text`, `check_inglese`, `check_grafica`, `check_plagiarism`, `english_user_id`, `graphic_user_id`, `plagiarism_user_id`, `email_utente`, `articolo`, `articolo_url`, `foto0_url`, `foto1_url`, `foto2_url`, `foto3_url`, `foto4_url`, `foto5_url`, `foto6_url`, `foto7_url`, `foto8_url`, `foto9_url`, `foto0_original_name`, `foto1_original_name`, `foto2_original_name`, `foto3_original_name`, `foto4_original_name`, `foto5_original_name`, `foto6_original_name`, `foto7_original_name`, `foto8_original_name`, `foto9_original_name`, `paypal_amount`, `user_id`, `uniq_id`, `created`) values ('1414', '1414', '12', '22', 'Invia', '', '', '1', '1', '0', '0', '0', '0', '', '', '', 'giorgio.magno85+1@gmail.com', '1414_Errori_dmb.docx', 'articoli/201512041612_655_1414/1414_Errori_dmb.docx', 'articoli/201512041612_655_1414/1414_dmb_contatti.png', 'articoli/201512041612_655_1414/1414_ftgoogle122014.png', '', '', '', '', '', '', '', '', 'dmb_contatti.png', 'ftgoogle122014.png', '', '', '', '', '', '', '', '', '0.66', '655', 'f65a71457180441ed489dd32910fb9d717904a00', '2015-12-04 16:12:35');
                        )

                )

        )

    [25] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                        )

                )

        )

)
GreyHead 05 Dec, 2015
Hi livingwebstudio,

Please check your code - you shouldn't be getting names like [foto0_url] from the code I posted - it would be [foto][0][[url] Could be there's a typo in my code but I don't see it.

Bob
livingwebstudio 05 Dec, 2015
hi Bob,
the code that you seen it'here because now I save all the data of uploaded file in one db.
I have this code
$form->data['foto0_url'] = $form->files['foto']['0']['link'];
$form->data['foto1_url'] = $form->files['foto']['1']['link'];
$form->data['foto2_url'] = $form->files['foto']['2']['link'];
$form->data['foto3_url'] = $form->files['foto']['3']['link'];
$form->data['foto4_url'] = $form->files['foto']['4']['link'];
$form->data['foto5_url'] = $form->files['foto']['5']['link'];
$form->data['foto6_url'] = $form->files['foto']['6']['link'];
$form->data['foto7_url'] = $form->files['foto']['7']['link'];
$form->data['foto8_url'] = $form->files['foto']['8']['link'];
$form->data['foto9_url'] = $form->files['foto']['9']['link'];
$form->data['foto0_original_name'] = $form->files['foto']['0']['original_name'];
$form->data['foto1_original_name'] = $form->files['foto']['1']['original_name'];
$form->data['foto2_original_name'] = $form->files['foto']['2']['original_name'];
$form->data['foto3_original_name'] = $form->files['foto']['3']['original_name'];
$form->data['foto4_original_name'] = $form->files['foto']['4']['original_name'];
$form->data['foto5_original_name'] = $form->files['foto']['5']['original_name'];
$form->data['foto6_original_name'] = $form->files['foto']['6']['original_name'];
$form->data['foto7_original_name'] = $form->files['foto']['7']['original_name'];
$form->data['foto8_original_name'] = $form->files['foto']['8']['original_name'];
$form->data['foto9_original_name'] = $form->files['foto']['9']['original_name'];
livingwebstudio 05 Dec, 2015
in setup I have
DB SAVE in wich I save my first data;
CUSTOM CODE fore the path of my file
<?php
$user = JFactory::getUser();
$id_utente=$user->get('id');
$email_utente=$user->get('email');
$form->data['email_utente'] = $email_utente;
$titolo = substr(preg_replace('/\s+/', '', $form->data['titolo']), 0, 30);
$form->actions_config[2]["upload_path"] = "articoli".DS.date("YmdHi")."_".$id_utente."_".$titolo.DS;
?>

FILE UPLOAD
CUSTOM CODE
<?php
$foto = array();
foreach ( $form->files['foto'] as $k => $f ) {
  $foto[$k]['record_id'] = $form->data['id']; // the Articolo record id
  $foto[$k]['name'] = $f['name'];
  $foto[$k]['original_name'] = $f['original_name'];
  $foto[$k]['path'] = $f['path'];
  $foto[$k]['size'] = $f['size'];
  $foto[$k]['link'] = $f['link'];
  );
}
$form->data['foto'] = $foto;
?>

DB SAVE for Foto data (only MULTI is set up)
I have this table for foto
id	int(11) Auto incremento	 
record_id	int(11)	 
name	varchar(255)	 
original_name	varchar(255)	 
path	varchar(255)	 
size	varchar(255)	 
link	varchar(255)

this is entire debug
Data Array
Array
(
    [chronoform] => Articolo-new
    [event] => submit
    [titolo] => dddd
    [autori_##] => 
    [autori_1] => ccc
    [contenuti_extra] => 
    [caratteri] => 33
    [invia] => Invia
    [giudizio_text] => 
    [giudizio_inglese] => 
    [giudizio_grafica] => 1
    [giudizio_plagiarism] => 1
    [check_text] => 0
    [check_inglese] => 0
    [check_grafica] => 0
    [check_plagiarism] => 0
    [english_user_id] => 
    [graphic_user_id] => 
    [plagiarism_user_id] => 
    [id] => 80
    [email_utente] => giorgio.magno85@gmail.com
    [articolo] => dddd_Business_plan.docx
    [foto] => Array
        (
            [0] => dddd_favico_-_Copia_2.png
            [1] => dddd_favico_-_Copia.png
            [2] => dddd_favico.png
            [id] => 0
        )

)
Array
(
    [articolo] => Array
        (
            [name] => dddd_Business_plan.docx
            [original_name] => Business_plan.docx
            [path] => articoli/201512051430_645_dddd/dddd_Business_plan.docx
            [size] => 11672
            [link] => articoli/201512051430_645_dddd/dddd_Business_plan.docx
        )

    [foto] => Array
        (
            [0] => Array
                (
                    [name] => dddd_favico_-_Copia_2.png
                    [original_name] => favico_-_Copia_2.png
                    [path] => articoli/201512051430_645_dddd/dddd_favico_-_Copia_2.png
                    [size] => 16867
                    [link] => articoli/201512051430_645_dddd/dddd_favico_-_Copia_2.png
                )

            [1] => Array
                (
                    [name] => dddd_favico_-_Copia.png
                    [original_name] => favico_-_Copia.png
                    [path] => articoli/201512051430_645_dddd/dddd_favico_-_Copia.png
                    [size] => 16867
                    [link] => articoli/201512051430_645_dddd/dddd_favico_-_Copia.png
                )

            [2] => Array
                (
                    [name] => dddd_favico.png
                    [original_name] => favico.png
                    [path] => articoli/201512051430_645_dddd/dddd_favico.png
                    [size] => 16867
                    [link] => articoli/201512051430_645_dddd/dddd_favico.png
                )

        )

)
Errors
Array
(
)
Debug Info
Array
(
    [17] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `jm3_chronoengine_chronoforms_datatable_articolo` (`titolo`, `autori_1`, `contenuti_extra`, `caratteri`, `invia`, `giudizio_text`, `giudizio_inglese`, `giudizio_grafica`, `giudizio_plagiarism`, `check_text`, `check_inglese`, `check_grafica`, `check_plagiarism`, `english_user_id`, `graphic_user_id`, `plagiarism_user_id`, `user_id`, `uniq_id`, `created`) values ('dddd', 'ccc', '', '33', 'Invia', '', '', '1', '1', '0', '0', '0', '0', '', '', '', '645', '7d1c8091fdeb65e9627891ca574213d3c46bcd68', '2015-12-05 14:30:33');
                        )

                )

        )

    [2] => Array
        (
            [Files Upload] => Array
                (
                    [0] => Upload routine started for file upload by : articolo
                    [1] => articoli/201512051430_645_dddd/dddd_Business_plan.docx has been uploaded successfully.
                    [2] => Upload routine started for file upload by : foto
                    [3] => articoli/201512051430_645_dddd/dddd_favico_-_Copia_2.png has been uploaded successfully.
                    [4] => Upload routine started for file upload by : foto
                    [5] => articoli/201512051430_645_dddd/dddd_favico_-_Copia.png has been uploaded successfully.
                    [6] => Upload routine started for file upload by : foto
                    [7] => articoli/201512051430_645_dddd/dddd_favico.png has been uploaded successfully.
                )

        )

    [32] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                        )

                )

        )

)

the second DB SAVE doesn't work..
GreyHead 05 Dec, 2015
Hi livingwebstudio,

I'm sorry but I am lost - I have no idea what you are trying to do now :-(

I gave you code to save multiple records - and you've converted it back to a single record , . .

Bob
livingwebstudio 05 Dec, 2015
i'm tryng to save as many row as are the files i'm uploading.
I posted before all the process.. the setup of my form and the debug.
I put the code that you gave me
I set up the DB SAVE action only in MULTI but it doesn't work..
livingwebstudio 05 Dec, 2015
Answer
Ok now it works, I found the error in the code
<?php
$foto = array();
foreach ( $form->files['foto'] as $k => $f ) {
  $foto[$k]['record_id'] = $form->data['id']; // the Articolo record id
  $foto[$k]['name'] = $f['name'];
  $foto[$k]['original_name'] = $f['original_name'];
  $foto[$k]['path'] = $f['path'];
  $foto[$k]['size'] = $f['size'];
  $foto[$k]['link'] = $f['link'];
}
$form->data['foto'] = $foto;

this is correct
moreover the DB SAVE have to set up with multisave and MODEL ID yes with ID foto.
Thanks!
This topic is locked and no more replies can be posted.