miniBB ® 

miniBB

®
Support Forums
  
 | Start | Register | Search | Statistics | File Bank | Manual |
Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /  
 

How to customize custom fields format for use with email templates?

 
Author Karel
Partaker
#1 | Posted: 19 Oct 2020 22:52 
There is a comprehensive article named Extending miniBB's User Profile with the New Field(s) covering various conversions of stored values so that they display nicely on profile page, alongside forum messages, etc.

I wonder whether it is also possible to "non-destructively" pass these transformed values to e-mail templates.

Fictional scenario (similiar to my real scenario):

I use the Gender add-on, allowing users to specify their gender during registration. The value is stored as integer, 0 = none, 1 = Male, 2 = Female. I want to add this information to the e-mail template email_admin_userregister_eng.txt, but in a readable form.

When I add the line

...
Gender: {$user_custom3}
...

to the email_admin_userregister_eng.txt template, the generated e-mail will look like this

...
Gender: 2
...

which is not what I want to achieve.

I can add the required transformation to the bb_func_regusr.php...

if ($emailadmin==1 and $genEmailDisable!=1) {
$genderselected=$genders[$user_custom3];
$emailMsg=operate_string(ParseTpl(makeUp('email_admin_userregister_'.$langOrig)), TRUE);
$sub=explode('SUBJECT>>', $emailMsg); $sub=explode('<<', $sub[1]); $emailMsg=trim($sub[1]); $sub=$sub[0];
sendMail($admin_email, $sub, $emailMsg, $reply_to_email, $reply_to_email);
}

and modify email_admin_userregister_eng.txt like this

...
Gender: {$genderselected}
...

Then it works, i.e. generated e-mail looks like this

...
Gender: Female
...

But it is not a good idea since bb_func_regusr.php is one of the core files and can be overwritten anytime during miniBB update.

I also tried to nest variables in the e-mail template definition, but the parser does not support such a thing and renders "{$genders[{user_custom3}]}" as "$genders[2]", not as "Female".

So I would like to ask about possibly better ideas on how to achieve this.

Author tom322
Active Member
#2 | Posted: 20 Oct 2020 17:59 
Maybe leaving the customized templates and adding $genderselected to the bb_plugins.php would work, like:

if($action=='register' and $emailadmin==1) $genderselected=$genders[$user_custom3]; else $genderselected='';

Author Karel
Partaker
#3 | Posted: 20 Oct 2020 20:20 
tom322:
Maybe leaving the customized templates and adding $genderselected to the bb_plugins.php would work, like:

if($action=='register' and $emailadmin==1) $genderselected=$genders[$user_custom3]; else $genderselected='';

Thanks for the hint. It seems that value of $user_custom3 is unknown to bb_plugins.php, but after several more tries I have discovered that adding it to bb_plugins_user.php works. In the Gender add-on it would be

elseif(($enableNewRegistrations and $action=='register') or ($enableProfileUpdate and $action=='editprefs')){
if(isset($_POST['user_custom3'])) $user_custom3=(int)$_POST['user_custom3']+0;
$genderselected=$genders[$user_custom3];
}

Author Paul
Lead Developer 
#4 | Posted: 21 Oct 2020 02:20 
Karel
So, did your solution actually solve your task?..

If so, it's perfect, but... may I know why it could be important to pass this value to an admin registration email? I.e. if you pass it to such email, what's the purpuse to distinct the gender at such level? Just curious.

Author Karel
Partaker
#5 | Posted: 21 Oct 2020 07:15 
Paul:
I.e. if you pass it to such email, what's the purpuse to distinct the gender at such level?
Yes, it works, thank you. I used gender only as an example (because there is a gender add-on available so I used its code to better explain what I want to achieve). I do not actually ask my users for gender information, but I have another two Yes/No custom fields implemented in the same way — and I wanted to receive this information in the registration e-mail so I know that someone registered and wants (or not) to receive some e-mail notifications in the future and take part (or not take part) in some "lottery draw" to win a free ebook (or not). Just out of curiosity, it does not affect the functionality in any way.

Author Paul
Lead Developer 
#6 | Posted: 21 Oct 2020 20:13 
Karel
It makes sense. Thanks for explanation!

Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /
 How to customize custom fields format for use with email templates?
 Share Topic's Link

Your Reply Click this icon to move up to the quoted message


  ?
Post as a Guest, leaving the Password field blank. You could also enter a Guest name, if it's not taken by a member yet. Sign-in and post at once, or just sign-in, bypassing the message's text.


Before posting, make sure your message is compliant with forum rules; otherwise it could be locked or removed with no explanation.

 

 
miniBB Support Forums Powered by Forum Software miniBB ® Home  Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contact Us
Proceed with the Captcha add-on: protect your miniBB-forums from the automated spam and flood.


  ⇑