Forums

get record ID and use it as filename

mariospapa 31 Jul, 2010
How can i get the Record ID when i submit a form with JRequest::getCmd feature an use it as a filename of uploaded file attached with the form?

I want something like this:
$filename = JRequest::get('cf_id', 'blank', 'post').'.doc';

When i write the above line in FileName format field of a Chronoform it always upload a file with blank.doc as a filename. For example, if the record id is 26 then i would like to have a filename like this 26.doc. How can i grab this info from cf_id column of a stored table in sql? The cf_id number is generated automatically from the system.
GreyHead 31 Jul, 2010
Hi mariospapa,

The file uploading and naming is done before the form data is saved to the database so cf_id doesn't exist.

The easiest way to do this would be to rename the uploaded file in the OnSubmit After box - making sure that you set this to run *after* the Autogenerated code in the 'RunOrder' tab.

Bob
mariospapa 31 Jul, 2010
I wrote the following php code "On Submit code - after sending email:" and change the 'RunOrder' of this code after the AutoGenerated Code, but nothing happened. Can u see any mistake?
<?php
rename("/public_html/components/com_chronocontact/uploads/files/oldfilename.doc", "/public_html/components/com_chronocontact/uploads/files/newfilename.doc");
?>


PS. Oldfilename.doc exists after submitting the corresponding chronoform.
GreyHead 01 Aug, 2010
Hi mariospapa,

The PHP looks OK, I can only assume that there is some other problem with the paths or with setting the file names?? Hard to say without seeing all the code and preferably the Form DEbug output too.

Bob
mariospapa 01 Aug, 2010
Thank you Bob!

I managed to rename the submitted file from a chronoform with the aforementioned php command "rename". Can you tell me please how can I use for new file name a field from a table in MySQL? Let's say the record id as I wrote to my older posts. In other words, something like this:

<?php
rename("/public_html/components/com_chronocontact/uploads/files/oldfilename.doc", "/public_html/components/com_chronocontact/uploads/files/{cf_id}.doc");
?>


The above command didn't work, because it renames the oldfilename.doc to {cf_id}.doc and i want to rename it to 26.doc, if my cf_id is 26. Can you write me the correct command with the parametric field inside?
GreyHead 15 Aug, 2010
Hi mariospapa,

This code should let you get the value of cf_id provided that it runs after the Autogenerated Code (you can change the order in the Run Order tab).
$cf_id = $MyForm->tablerow["jos_chronoforms_my_form_name"]->cf_id; 



Bob
This topic is locked and no more replies can be posted.