How can I query the current login user, and add that as the output filename.

Formidable Forms
3 May, 2024 14:52:11
CaptPopham
Topics: 1
Messages: 1
I have a button that once pushed, I need to save into a particular folder, and I'd like the file name to contain a few different metas from the PDF. Ideally, I would like the output of this file to be /public_html/wp-content/uploads/025.05.03.2024.asset.01.pdf

Where 025 would be the current logged in Wordpress wp-users user number(from our wordpress database), date, asset name from page two of our fomidable form (ID 150 and/or Field Key w9br), 1st (2ed, 3ed. 4th, etc) edition and stored in a specific location. With this data I want to populate the users profile by their wp-user number.

I have played around with e2pdf-save, e2pdf-user, but I am having trouble wrapping my head around the correct shortcode to attach to a button of the confirmation page under the e2pdf-view box. Can someone give me a couple examples of what the correct shortcode would look like? I don't mind editing the php files if I need. Sorry that I am a noobie :)

Thanks so much an advanced for any and all help.
Bryan
4 May, 2024 01:18:19
E2Pdf
Support
Topics: 7
Messages: 3577
Hello,

It would require PHP and JS knowledge. One of the possible solutions:

1. You must create the button to trigger an Ajax call and pass the Entry ID to your main PHP function to generate and save PDF.

It must be possible to generate JS code by using the [id] - shortcode in the "Success Message" / Formidable Forms View. An example of creating such call in the 1st accepted answer: https://wordpress.stackexchange.com/questions/313643/how-to-call-a-php-function-with-ajax-when-the-user-clicks-a-button.

2. Set the "PDF Local Name" (the screenshot is attached) to:

[e2pdf-format-output sprintf="%03d"][e2pdf-user id="current"][/e2pdf-format-output].[e2pdf-format-date format="d.m.Y"]now[/e2pdf-format-date].[150]

By default, it must save a PDF with the name: 025.05.03.2024.asset.pdf. As you can see there is no yet index in the end, we will get back to it later.

3. In the PHP function that will generate the code, that is used for Ajax call, it needs to use the logic as follows:

$pdf = do_shortcode('[e2pdf-save id="1" dataset="' . $entry_id . '" dir="wp-content/uploads/" output="path" apply="true"]');

* where $entry_id - is the Entry ID passed via JS / Ajax call to PHP

The $pdf variable will contain the path to the generated and saved PDF. At that stage, the PDF will be saved as: wp-content/uploads/025.05.03.2024.asset.pdf

After that, when you have the PDF generated, you need to manipulate that saved PDF to add the index to the end. For example, you can extract the PDF name, count the PDF files that start with the same name, create the required index 01, 02, 03, etc, add it to the end of the name, and rename the current PDF.

We would really appreciate your feedback at WordPress.org!