No Code Attached Yet
avatar keewhip
keewhip
15 Jul 2022

Steps to reproduce the issue

Create a user required custom field named "test"
Show this field on registration page
Include this field in the new user mailtemplate using the code {COM_FIELDS}test{/COM_FIELDS}
Register an new user account

Expected result

When user creates a new account, this placeholder in the email should be replaced with submitted value

Actual result

The placeholder is replaced with a empty string

System information (as much as possible)

/libraries/src/Mail/MailTemplate.php
Function replaceTags handles the replacements

on line 354-360 it is missing the code to supply the replacement if this is not an array:

Additional comments

Change this code for a fix

foreach ($value as $subvalue)
{
	if (is_array($subvalue))
	{
		$replacement .= $this->replaceTags($matches[1][$i], $subvalue);
	}
}

to

foreach ($value as $name => $subvalue)
{
	if (is_array($subvalue))
	{
		$replacement .= $this->replaceTags($matches[1][$i], $subvalue);
	}
	elseif (is_string($subvalue) && $name == $matches[1][$i])
	{
		$replacement .= $subvalue;
	}
}
avatar keewhip keewhip - open - 15 Jul 2022
avatar keewhip keewhip - change - 15 Jul 2022
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 15 Jul 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 Jul 2022
avatar chmst
chmst - comment - 20 Jul 2022

Thank you for reporting, @keewhip .
Would you like to make a PR for your solution?

avatar keewhip
keewhip - comment - 20 Jul 2022

Not checking for field name caused a loopback error in the code.
updated code lines 354-364 /libraries/src/Mail/MailTemplate.php

                        foreach ($value as $name => $subvalue)
                        {
                            if (is_array($subvalue) && $name == $matches[1][$i])
                            {
                                $replacement .= implode("\n", $subvalue);
                            }
                            elseif (is_string($subvalue) && $name == $matches[1][$i])
                            {
                                $replacement .= $subvalue;
                            }
                        }

will make a PR

avatar alikon
alikon - comment - 20 Jul 2022

please test #38305

avatar alikon alikon - change - 20 Jul 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-07-20 09:33:58
Closed_By alikon
avatar alikon alikon - close - 20 Jul 2022

Add a Comment

Login with GitHub to post a comment