Hello I want to save the name of the pdf that its created with TCPDF using the data of a field in my chronoform
When I submit the information in my chronoform the pdf its saved with the chronoform name, but i want to use the number of the "ID_Tienda" field so the pdf can be saved with this number ,the date , and the hour.
Thanks for your help
When I submit the information in my chronoform the pdf its saved with the chronoform name, but i want to use the number of the "ID_Tienda" field so the pdf can be saved with this number ,the date , and the hour.
Thanks for your help
Hi angelmorales,
I think that the simplest answer to this is to add a Custom Code action after the PDF file is created and re-name it there??
Bob
I think that the simplest answer to this is to add a Custom Code action after the PDF file is created and re-name it there??
Bob
The best practice its that the save name its generated automatically, but if you can help me with the custom Code it would be great!!
Thanks for your answer
Thanks for your answer
Hi angelmorales,
This code in a Custom Code action after the TCPDF action will allow you to rename the file.
In your case the new name line might be
Bob
This code in a Custom Code action after the TCPDF action will allow you to rename the file.
<?php
jimport('joomla.filesystem.file');
// copy the entry from the 'File name in Data/Files array' setting
$data_file_name = 'cf_pdf_file';
$name = $form->files[$data_file_name]['name'];
$path = $form->files[$data_file_name]['path'];
// remove the file name from the full path
$path = str_replace($name, '', $path);
if ( !JFile::exists($path.$name) ) {
echo 'File not found';
return false;
}
$ext = JFile::getExt($path.$name);
// create a new name here - can use $form->data
$new_name = 'new_name';
$new_name .= '.'.$ext;
// rename the file
JFile::move($path.$name, $path.$new_name);
// update the $form->files values
$form->files[$data_file_name]['name'] = $new_name;
$form->files[$data_file_name]['path'] = $path.$new_name;
// fix URL bug
$url = str_replace(JPATH_SITE.'/', JURI::root(), $path);
$form->files[$data_file_name]['link'] = $url.$new_name;
?>
In your case the new name line might be
$new_name = $form->data['ID_Tienda'].date('YmdH');
Bob
Hello, I put the code in a Custom Code action after the TCPDF action, then i submit the form but the file its created without allowing me to rename the file and its saved with tha chronoform name and the legend "File not found" printed in the left corner of the pdf file
Sorry for the stupid question but in wich part of the code I have to include the new name line:
Thanks for your patience and help
Sorry for the stupid question but in wich part of the code I have to include the new name line:
$new_name = $form->data['ID_Tienda'].date('YmdH');
;
Thanks for your patience and help
Hi angelmorales,
Here
Bob
Here
// create a new name here - can use $form->data
$new_name = 'new_name';
Bob
I include the code in the Custome Code like this:
But it doesnt work, It doesn aloud me to rename the save file and it doesnt save it with the 'ID_Tienda' data and the date
The generated pdf file saved prints in the left top corner the legend "File not found"
Thanks for your help
<?php
jimport('joomla.filesystem.file');
// copy the entry from the 'File name in Data/Files array' setting
$data_file_name = 'cf_pdf_file';
$name = $form->files[$data_file_name]['name'];
$path = $form->files[$data_file_name]['path'];
// remove the file name from the full path
$path = str_replace($name, '', $path);
if ( !JFile::exists($path.$name) ) {
echo 'File not found';
return false;
}
$ext = JFile::getExt($path.$name);
// create a new name here - can use $form->data
$new_name = 'new_name';
$new_name .= '.'.$ext;
$new_name = $form->data['ID_Tienda'].date('YmdH');
// rename the file
JFile::move($path.$name, $path.$new_name);
// update the $form->files values
$form->files[$data_file_name]['name'] = $new_name;
$form->files[$data_file_name]['path'] = $path.$new_name;
// fix URL bug
$url = str_replace(JPATH_SITE.'/', JURI::root(), $path);
$form->files[$data_file_name]['link'] = $url.$new_name;
?>
But it doesnt work, It doesn aloud me to rename the save file and it doesnt save it with the 'ID_Tienda' data and the date
The generated pdf file saved prints in the left top corner the legend "File not found"
Thanks for your help
Sorry for my misspelling:
But it doesnt work, It doesnt allow me to rename the save file and it doesnt save it with the 'ID_Tienda' data and the date.
The generated pdf file saved prints in the left top corner the legend "File not found"
Thanks for your help
But it doesnt work, It doesnt allow me to rename the save file and it doesnt save it with the 'ID_Tienda' data and the date.
The generated pdf file saved prints in the left top corner the legend "File not found"
Thanks for your help
Hi angelmorales,
You have the $new_file line in the wrong place. The code should still work though the file might be missing the ,pdf extension.
I tested again in CFv4 (on Joomla! 3 in my case) and the code below works correctly. BUT I had to make one modification to the form action:
+ Edit the file /administrator/components/com_chronoforms/form_actions/tcpdf/cfaction_tcpdf.php and right at the end comment out these lines
Bob
You have the $new_file line in the wrong place. The code should still work though the file might be missing the ,pdf extension.
I tested again in CFv4 (on Joomla! 3 in my case) and the code below works correctly. BUT I had to make one modification to the form action:
+ Edit the file /administrator/components/com_chronoforms/form_actions/tcpdf/cfaction_tcpdf.php and right at the end comment out these lines
// $mainframe = JFactory::getApplication();
// $mainframe->close();
They stop any further processing so the Custom Code after the TCPDF action doesn't run. You must also set the TCPDF action to Save to Server.
Bob
<?php
jimport('joomla.filesystem.file');
// copy the entry from the 'File name in Data/Files array' setting
$data_file_name = 'cf_pdf_file';
$name = $form->files[$data_file_name]['name'];
$path = $form->files[$data_file_name]['path'];
// remove the file name from the full path
$path = str_replace($name, '', $path);
if ( !JFile::exists($path.$name) ) {
echo 'File not found';
return false;
}
$ext = JFile::getExt($path.$name);
// create a new name here - can use $form->data
$new_name = $form->data['ID_Tienda'].date('YmdH');
$new_name .= '.'.$ext;
// rename the file
$test = JFile::move($path.$name, $path.$new_name);
// update the $form->files values
$form->files[$data_file_name]['name'] = $new_name;
$form->files[$data_file_name]['path'] = $path.$new_name;
// fix URL bug
$url = str_replace(JPATH_SITE.'/', JURI::root(), $path);
$form->files[$data_file_name]['link'] = $url.$new_name;
$form->debug[] = print_r($form->files, true);
?>
It doesnt work in my form
I copy the code to the costume Code
I Edit the file /administrator/components/com_chronoforms/form_actions/tcpdf/cfaction_tcpdf.php
Bute it keep printing "File not found" in the pdf file
It doesnt use the ID_Tienda field and date to name the saved file
Now when i sumbit the form it doesnt show the pdf file anymore , now it shows the format of the form with the results and in the end it shows some kind of code (Image 7)
I dont know whts wrong,hope you cand help me
Thanks
I copy the code to the costume Code
I Edit the file /administrator/components/com_chronoforms/form_actions/tcpdf/cfaction_tcpdf.php
Bute it keep printing "File not found" in the pdf file
It doesnt use the ID_Tienda field and date to name the saved file
Now when i sumbit the form it doesnt show the pdf file anymore , now it shows the format of the form with the results and in the end it shows some kind of code (Image 7)
I dont know whts wrong,hope you cand help me
Thanks
Hi angelmorales,
I've lost track of what code you have where :-(
"I Edit the file /administrator/components/com_chronoforms/form_actions/tcpdf/cfaction_tcpdf.php" - Why and how did you edit this file?
I tested the code that I posted and it works correctly.
Bob
I've lost track of what code you have where :-(
"I Edit the file /administrator/components/com_chronoforms/form_actions/tcpdf/cfaction_tcpdf.php" - Why and how did you edit this file?
I tested the code that I posted and it works correctly.
Bob
It works ! This is the problem:
I change the Mode Field to "VIEW" in the Costume Code (Image 1) and I comment the following lines:
And the pdf file saves with the ID_Tienda field and the date.
Know I have and issue, before I made this changes when I submit the form the pdf was saved and the pdf was displayed in the screen so I can print it, now when I submit the form, the form its saved and the data shows in the screen (Image 2 and 3) and i cant print the pdf.
Its there a way to send the pdf file to print automatically when i submit the form or be displayed in the screen ?
Thanks for your help you are really helping me!
I change the Mode Field to "VIEW" in the Costume Code (Image 1) and I comment the following lines:
// $mainframe = JFactory::getApplication();
// $mainframe->close();
And the pdf file saves with the ID_Tienda field and the date.
Know I have and issue, before I made this changes when I submit the form the pdf was saved and the pdf was displayed in the screen so I can print it, now when I submit the form, the form its saved and the data shows in the screen (Image 2 and 3) and i cant print the pdf.
Its there a way to send the pdf file to print automatically when i submit the form or be displayed in the screen ?
Thanks for your help you are really helping me!
Hi angelmorales,
I think that using a File Download action after the Custom Code that renames the file should let you download it in the way you want.
Bob
I think that using a File Download action after the Custom Code that renames the file should let you download it in the way you want.
Bob
I put the File Download Action after the Costume Code , but i try to use the File Name Path field of the File Download Action, why? because i want to download the pdf that its generated when the submit button its used,but i get an error and the pdf file doesnt download.
I use the File Name field of the File Download Action just to give a try , it works but only for download static files.
Thanks for your help
I use the File Name field of the File Download Action just to give a try , it works but only for download static files.
Thanks for your help
Hi angelmorales,
Sorry, you are right. The DownLoad files action only works for a fixed file name and path.
I got this code to work in Chrome - it downloads the renamed file.
Bob
Sorry, you are right. The DownLoad files action only works for a fixed file name and path.
I got this code to work in Chrome - it downloads the renamed file.
<?php
$file_path = $form->files['cf_pdf_file']['path'];
if ( file_exists($file_path) ) {
\GCore\Libs\Download::send($file_path);
}
?>
Note that cf_pdf_file may need to be changed if that is set differently in the TCPDF action.
Bob
I create a new Custome Code, I put the code, but when I submit the form , the pdf doesnt download , and shows an error message.
The pdf file its saved in the server with the correct name.
Thanks for your help
The pdf file its saved in the server with the correct name.
Thanks for your help
Hello I still have the problem, I try to put Save+Download in the View otion in the TCPDF option, It saves the file in the server and my desktop, but it save with the form name ,I try to open the file but it shows an error.
Can you tell me what Im doing wrong with the code that Grayhead share to me.
Thanks for your help
Can you tell me what Im doing wrong with the code that Grayhead share to me.
Thanks for your help
Any help?
Thanks
Thanks
Hi angelmorales,
You can't rename the file until after it has been created. The Custom Code has to be run after the TCPDF action completes. So if you try to download it directly from the TCPDF action it won't be renamed. Also if the TCPDF is set to Download then it takes over control and no later actions will run.
Bob
You can't rename the file until after it has been created. The Custom Code has to be run after the TCPDF action completes. So if you try to download it directly from the TCPDF action it won't be renamed. Also if the TCPDF is set to Download then it takes over control and no later actions will run.
Bob
Im going to describe the order of the actions(Image "Actions"):
1-I have the TCPDF Action ( I post the images:"tcpdf1" "tcpdf2")
2-Custome Code to rename file saved (Image: "custome code rename file saved")
3-Custome Code to download the renamed file (Image: "custome code download")
When I submit this happens:
The pdf its saved and renamed in the server but it doesnt download right the way I submit the button , an error shows in the screen (Image: "Error")
IThanks for your help
1-I have the TCPDF Action ( I post the images:"tcpdf1" "tcpdf2")
2-Custome Code to rename file saved (Image: "custome code rename file saved")
3-Custome Code to download the renamed file (Image: "custome code download")
When I submit this happens:
The pdf its saved and renamed in the server but it doesnt download right the way I submit the button , an error shows in the screen (Image: "Error")
IThanks for your help
Hello , any help? please dont misunderstand me , you have help me a lot and i am very grateful , but I have to know if I have to look in another place , maybe because I have not a lot of programming experience, and I know that you are helping a lot of people.
Thanks for your help , hope you can answer me , you are doing and excellent job.
Thanks for your help , hope you can answer me , you are doing and excellent job.
I have not found the answer, thanks anyway for your help 😉
Hi ,
Sorry, looking back at the thread this code is using the GCore library which is installed with CFv5 - but not with CFv4.
Bob
Sorry, looking back at the thread this code is using the GCore library which is installed with CFv5 - but not with CFv4.
<?php
$file_path = $form->files['cf_pdf_file']['path'];
if ( file_exists($file_path) ) {
\GCore\Libs\Download::send($file_path);
}
?>
Does the CFv4 File DownLoader action work here? Using the File Name Path option should work OK.
Bob
Hello , I try to use the code in chronoformsV5 but it doesnt work, in chronoformsv4 works fine, could you tell me where do I found the cfaction_tcpdf .php file in chronoformsV5 , I want to comment the lines:
//$mainframe =& JFactory::getApplication();
//$mainframe->close();
Maybe thats the problem
Im using this code:
THANKS!
//$mainframe =& JFactory::getApplication();
//$mainframe->close();
Maybe thats the problem
Im using this code:
<?php
jimport('joomla.filesystem.file');
// copy the entry from the 'File name in Data/Files array' setting
$data_file_name = 'cf_pdf_file';
$name = $form->files[$data_file_name]['name'];
$path = $form->files[$data_file_name]['path'];
// remove the file name from the full path
$path = str_replace($name, '', $path);
if ( !JFile::exists($path.$name) ) {
echo 'File not found';
return false;
}
$ext = JFile::getExt($path.$name);
// create a new name here - can use $form->data
$new_name = $form->data['ID_Tienda'].date('dmYHis');
$new_name .= '.'.$ext;
// rename the file
$test = JFile::move($path.$name, $path.$new_name);
// update the $form->files values
$form->files[$data_file_name]['name'] = $new_name;
$form->files[$data_file_name]['path'] = $path.$new_name;
// fix URL bug
$url = str_replace(JPATH_SITE.'/', JURI::root(), $path);
$form->files[$data_file_name]['link'] = $url.$new_name;
$form->debug[] = print_r($form->files, true);
?>
THANKS!
Hi amgelmorales,
Please check my answer for CFv5 earlier in this thread. As far as I know that works OK.
Bob
Please check my answer for CFv5 earlier in this thread. As far as I know that works OK.
Bob
The solution for customize the Save Name TCPDF in Chronoforms V4 that works for me was:
Step 1: Inserting a Custome Code after HTML to PDF with the following code ( In this example the save name its obtained from the following data : "ID_Tienda" and date) :
Step 2: Comment the following lines from the file : administrator/components/chronoforms-form_actions-tcpdf-cfaction_tcpdf.php
In Chronoforms V5 folders I cant find the cfaction_tcpdf.php file and the "mainframe" lines
Step 3:In Chronoforms V4 in HTML to PDF in the Settings tab , In Mode Option I put View , but In Chronoforms V5 that option doesnt exists
My Results in Chronoforms V5 its that the PDF its generated and the file its saved in the Document Save Path, but the name Customize Save Name doesnt works
Thanks for your help!
Step 1: Inserting a Custome Code after HTML to PDF with the following code ( In this example the save name its obtained from the following data : "ID_Tienda" and date) :
<?php
jimport('joomla.filesystem.file');
// copy the entry from the 'File name in Data/Files array' setting
$data_file_name = 'cf_pdf_file';
$name = $form->files[$data_file_name]['name'];
$path = $form->files[$data_file_name]['path'];
// remove the file name from the full path
$path = str_replace($name, '', $path);
if ( !JFile::exists($path.$name) ) {
echo 'File not found';
return false;
}
$ext = JFile::getExt($path.$name);
// create a new name here - can use $form->data
$new_name = $form->data['ID_Tienda'].date('dmYHis');
$new_name .= '.'.$ext;
// rename the file
$test = JFile::move($path.$name, $path.$new_name);
// update the $form->files values
$form->files[$data_file_name]['name'] = $new_name;
$form->files[$data_file_name]['path'] = $path.$new_name;
// fix URL bug
$url = str_replace(JPATH_SITE.'/', JURI::root(), $path);
$form->files[$data_file_name]['link'] = $url.$new_name;
$form->debug[] = print_r($form->files, true);
?>
Step 2: Comment the following lines from the file : administrator/components/chronoforms-form_actions-tcpdf-cfaction_tcpdf.php
//$mainframe =& JFactory::getApplication();
//$mainframe->close();
In Chronoforms V5 folders I cant find the cfaction_tcpdf.php file and the "mainframe" lines
Step 3:In Chronoforms V4 in HTML to PDF in the Settings tab , In Mode Option I put View , but In Chronoforms V5 that option doesnt exists
My Results in Chronoforms V5 its that the PDF its generated and the file its saved in the Document Save Path, but the name Customize Save Name doesnt works
Thanks for your help!
Hi angelmorales,
As I said in my last post - please check the code for CFv5 posted earlier in this thread.
Bob
As I said in my last post - please check the code for CFv5 posted earlier in this thread.
Bob
[quote="GreyHead"]Hi angelmorales,
Sorry, you are right. The DownLoad files action only works for a fixed file name and path.
I got this code to work in Chrome - it downloads the renamed file.
Bob[/quote]
Thats the code that I use but it doesnt work.
In TCPDF, in the Option "VIEW" I put: Save+Display inline ,
In the "SAVE PATH" option I put the save path
In the "FILE NAME IN DATE" option, no change (Image1)
After TCPDF I put a Custome Code with the following code:
In the end I put another Custome Code with the code that you share to me:
[code]<?php
$file_path = $form->files['cf_pdf_file']['path'];
if ( file_exists($file_path) ) {
\GCore\Libs\Download::send($file_path);
}
?>[/code]
(Image2)
When I submit the form the PDF shows Inline in my chrome explorer,thats correct, because I can download the pdf from Chrome explorer , when I check the SAVE PATH the PDF its saved too, at this point everything its fine.
The problem its that the name of the file that its saved in the SAVE PATH hasnt been renamed with the data that I declare in the Custome Code:
Thanks for your attention
Sorry, you are right. The DownLoad files action only works for a fixed file name and path.
I got this code to work in Chrome - it downloads the renamed file.
<?php
$file_path = $form->files['cf_pdf_file']['path'];
if ( file_exists($file_path) ) {
\GCore\Libs\Download::send($file_path);
}
?>
Note that cf_pdf_file may need to be changed if that is set differently in the TCPDF action.
Bob[/quote]
Thats the code that I use but it doesnt work.
In TCPDF, in the Option "VIEW" I put: Save+Display inline ,
In the "SAVE PATH" option I put the save path
In the "FILE NAME IN DATE" option, no change (Image1)
After TCPDF I put a Custome Code with the following code:
<?php
jimport('joomla.filesystem.file');
// copy the entry from the 'File name in Data/Files array' setting
$data_file_name = 'cf_pdf_file';
$name = $form->files[$data_file_name]['name'];
$path = $form->files[$data_file_name]['path'];
// remove the file name from the full path
$path = str_replace($name, '', $path);
if ( !JFile::exists($path.$name) ) {
echo 'File not found';
return false;
}
$ext = JFile::getExt($path.$name);
// create a new name here - can use $form->data
$new_name = $form->data['ID_Tienda'].date('YmdH');
$new_name .= '.'.$ext;
// rename the file
$test = JFile::move($path.$name, $path.$new_name);
// update the $form->files values
$form->files[$data_file_name]['name'] = $new_name;
$form->files[$data_file_name]['path'] = $path.$new_name;
// fix URL bug
$url = str_replace(JPATH_SITE.'/', JURI::root(), $path);
$form->files[$data_file_name]['link'] = $url.$new_name;
$form->debug[] = print_r($form->files, true);
?>
In the end I put another Custome Code with the code that you share to me:
[code]<?php
$file_path = $form->files['cf_pdf_file']['path'];
if ( file_exists($file_path) ) {
\GCore\Libs\Download::send($file_path);
}
?>[/code]
(Image2)
When I submit the form the PDF shows Inline in my chrome explorer,thats correct, because I can download the pdf from Chrome explorer , when I check the SAVE PATH the PDF its saved too, at this point everything its fine.
The problem its that the name of the file that its saved in the SAVE PATH hasnt been renamed with the data that I declare in the Custome Code:
$new_name = $form->data['ID_Tienda'].date('YmdH');
, it keeps saving with the forms name (Image3)
Thanks for your attention
Success!! In TCPDF I change the VIEW option to SAVE TO SERVER , when I submit the form the pdf gets downloaded , and its saved in my SAVE PATH ,the pdf its renamed with the data that I declare in the Custome Code
That works form me , thanks!!!!
That works form me , thanks!!!!
Hi ,
Sorry, looking back at the thread this code is using the GCore library which is installed with CFv5 - but not with CFv4.
<?php
$file_path = $form->files['cf_pdf_file']['path'];
if ( file_exists($file_path) ) {
\GCore\Libs\Download::send($file_path);
}
?>
Does the CFv4 File DownLoader action work here? Using the File Name Path option should work OK.
Bob
How can I use this code with chronoforms v4 ? I try to use it but it shows an error
Thanks
This topic is locked and no more replies can be posted.