TOPIC:

User name in pdf attachments 4 years 5 months ago #222545

  • Topic Author
  • Lavett
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
I would like to include user name and user full name in the pdf attachments similar to the export pdf's. I've managed to create space for that in FORMNAME_pdf_attachment.pdf but I can't figure out what variable to use to get the names to show up in the pdf.

I could add elements for names in my form but since only logged in users are allowed to use the form it would be much easier to just get them from the system. I have looked at both export_pdf.php and mailtpl_txt.php (since user name and user full name are included in both) to get ideas but I can't figure out how to do it.

I would also like to include either user full name (preferred) or user name in the file name of the attached pdf. I have managed to personalize the file name with help from another thread in this forum but like above, I can't figure out how to include user full name or user name i the file name.

Please Log in or Create an account to join the conversation.

User name in pdf attachments 4 years 5 months ago #222588

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 416
Hello,

I think this is hardcoded somewhere in the BreezingForms code so you can use only those values that are already inside the PDF template. Therefore, unfortunatelly, you can't access the submitter user name and user full name.

The only way to do it is to add elements for names in your form as you said you knew you could.
I will give you instructions on how to do that, just in case:
1) Create a Hidden input element named username and in the Value field put this code:
<?php $user = JFactory::getUser(); return $user->username;?>

2) Create a Hidden input element named fullname and in the Value field put this code:
<?php $user = JFactory::getUser(); return "$user->name"; ?>

This part so far will solve including user name and user full name in the pdf attachments. To use that names in the title of pdf attachment do the following:

3) Go to \components\com_breezingforms\ and open the file facileforms.process.php.
Around line 5129 you have to replace this code:
$pdfname = $this->uploads . '/ffexport-pdf-' . $date_stamp . '-' . mt_rand(0, mt_getrandmax()) . '.pdf';
with this one:
       foreach($xmldata as $data){

            if ($data[_FF_DATA_TITLE]== "username"){$username=$data[_FF_DATA_VALUE];}
                if ($data[_FF_DATA_TITLE]== "fullname"){$fullname=$data[_FF_DATA_VALUE];}

                    }
                    if($this->formrow->name=='formname'){

                    $pdfname = $ff_compath . '/exports/'.$username.'_'.$fullname .'_'. $date_stamp.'.pdf';
                    }
                    else{

                $pdfname = $ff_compath . '/exports/ffexport-pdf-' . $date_stamp . '-' . mt_rand(0, mt_getrandmax()) . '.pdf';
            }
NOTE: In the code that I have sent you replace formname with the Name of your form. Also, if you gave other Titles to username and fullname, replace that as well.

Save the changes you've made and that should do the trick. Let me know if this will be acceptable solution for you.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

User name in pdf attachments 4 years 5 months ago #222591

  • Topic Author
  • Lavett
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
I don't think I said I knew how to get username and full name from the system and put them in a hidden element. I was talking about letting the user enter that information again in the form which would be impractical but your solution should do exactly what I want without any extra effort from the user.

I will try this at once. Thank you!

Please Log in or Create an account to join the conversation.

User name in pdf attachments 4 years 5 months ago #222593

  • mihaela
  • Offline
  • Developer
  • Developer
  • Posts: 3128
  • Karma: 105
  • Thanks: 416
Disregard my previous post. With additional searching I've found a way to out username and fullname in both pdf-attachment and it's name without creating new fields in your form.

To add username to the pdf file, use this code:
<?php $user = JFactory::getUser(); echo "$user->username"; ?>
To add full name to the pdf file, use this code:
<?php $user = JFactory::getUser(); echo "$user->name"; ?>

Furthermore, you can include the username and fullname to the name of pdf-export.
Go to \components\com_breezingforms\ and open the file facileforms.process.php.
Around line 5129 you have to replace this code:
<?php $user = JFactory::getUser(); return $user->username;?>
with this code:
            if($this->formrow->name=='formname'){
                        $usermy = JFactory::getUser(); 
                        $fullnamemy =$usermy->name;
                        $usernamemy = $usermy->username;

                    $pdfname = $ff_compath . '/exports/'.$usernamemy.'_'.$fullnamemy .'_'. $date_stamp.'.pdf';
                    }
                    else{

                $pdfname = $ff_compath . '/exports/ffexport-pdf-' . $date_stamp . '-' . mt_rand(0, mt_getrandmax()) . '.pdf';
            }
NOTE: In the code that I have sent you replace formname with the Name of your form.

Let me know if you managed to set this up for your form.
If you have more questions, feel free to ask.

Regards,

Mihaela

Please Log in or Create an account to join the conversation.

Last edit: Post by mihaela.

User name in pdf attachments 4 years 5 months ago #222598

  • Topic Author
  • Lavett
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
Getting name and user name into the pdf worked like a charm. Thank you.

I'm having a bit of a trouble with the title of the pdf though. I'm getting a syntax error from this row but since I'm not good at coding I can't figure out why.
$fullnamemy =$usermy->name;[size=][/size]

Please Log in or Create an account to join the conversation.

User name in pdf attachments 4 years 5 months ago #222600

  • Topic Author
  • Lavett
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 6
  • Thanks: 0
Sorry, figured it out now. What I can't figure out how the SIZE tag managed to sneak into my file. :)

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: ForumSupport
Time to create page: 0.107 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!