Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

email template

Questions related to installing, updating, setting up and configuring
sietwolt
Posts: 47
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 9 times
Been thanked: 1 time

email template

Unread post by sietwolt »

How can I link a email-template to a welcome email when adding an user? NOw it gives the message "Unknown email template!"
Is it also possible to link another welcome email to an other group of users ( for each group of users a own welcome email)? In the emailtemplate "nuWelcomeEmailTemplate" is a "category" - to wich field in new users can this be linked?
sietwolt
Posts: 47
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 9 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

The custom code in the form properties ( email template) looks empty but was in a former release of the nubuilder as below. I copied it in the properties of the present update but still error message when entering a new user with tick on ' send email' ; Unknown email template!


nuLabelOnTop(['emt_form_id']);
activeObj = $('#emt_body');

$('#emt_avail_fields').nuLabelOnTop();
nuSelectRemoveMultiple('emt_avail_fields');

if (nuEmailTemplateIsTemplate() && !nuDevMode()) {
nuDisableAllObjects();
nuMessage(`${nuTranslate('Error')}`, `${nuTranslate("Unable to save templates. Please clone them to create a new copy and save the cloned version instead.")}`, 3500);
}

nuEmailTemplateSetPreviewText();

function nuEmailTemplateAddSelectedField() {
const selObjectId = nuGetValue('emt_avail_fields', 'text');
const selObjectLabel = nuGetValue('emt_avail_fields');
if (selObjectId !== '') {
const activeObjectId = nuEmailTemplateGetActiveObjectId();
const isBody = activeObjectId == 'emt_body';
const label = isBody ? '<b>' + selObjectLabel + ': </b>': '';
nuInsertAtCaret(activeObjectId, label + "#" + selObjectId + "#" + (isBody ? '\n': ''));
$('#' + activeObjectId).trigger('change');
}
}


function nuEmailTemplateWrapText(elementID, openTag, closeTag) {
const textArea = $('#' + elementID);
const len = textArea.val().length;
const start = textArea[0].selectionStart;
const end = textArea[0].selectionEnd;
if (start !== end) {
var selectedText = textArea.val().substring(start, end);
var replacement = openTag + selectedText + closeTag;
textArea.val(textArea.val().substring(0, start) + replacement + textArea.val().substring(end, len)).trigger('change');
}
}

function nuEmailTemplateGetActiveObjectId() {
return activeObj.attr('id');
}

function nuEmailTemplateFormatText(tag) {
nuEmailTemplateWrapText(nuEmailTemplateGetActiveObjectId(), '<' + tag + '>', '</' + tag + '>');
}

function nuEmailTemplateFormatText2(tag) {
nuEmailTemplateWrapText(nuEmailTemplateGetActiveObjectId(), tag, tag);
}

function nuEmailTemplateSetPreviewText() {
$('#textAreaPreviewDiv').html($('#emt_body').val().replace(/\n/g, '<br />'));
}


function nuEmailTemplateIsTemplate() {
return nuGetValue('emt_template');
}

function nuOnClone() {

const code = emt_code.value;

if (nuEmailTemplateIsTemplate()) {
nuSetValue('emt_code', code.substring(0, code.length-8));
nuSetValue('emt_group', '');
nuSetValue('emt_template', false);
nuEnableAllObjects();
}

}
kev1n
nuBuilder Team
Posts: 4481
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 501 times
Contact:

Re: email template

Unread post by kev1n »

Which version of nuBuilder are you using?
sietwolt
Posts: 47
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 9 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Nubuilder 4.9.2
kev1n
nuBuilder Team
Posts: 4481
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 501 times
Contact:

Re: email template

Unread post by kev1n »

In nuBuilder 4.9.0, several procedure names were renamed. For example, nuWelcomeEmailTemplate was renamed to nu_send_welcome_email_template.

Could you please verify that the database version is also v4.9.2? You can check this via the Options menu → Version Info (or press Ctrl+Shift+V).
sietwolt
Posts: 47
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 9 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Database: MariaDB Server 10.6.20-MariaDB-cll-lve
PHP: 8.4.1
nuBuilder DB: V.4.9-2025.07.17.01
nuBuilder Files: V.4.9-2025.07.23.04

Attachement: emailtemplates in Templates
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4481
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 501 times
Contact:

Re: email template

Unread post by kev1n »

I noticed that the procedure nu_send_welcome_email_template still references the old email template name (nuWelcomeEmailTemplate) instead of "nu_send_welcome_email_template". This usually isn’t an issue, as most people rename the template anyway and use that updated name in their custom procedures.

You can run these two SQL updates (for example, in phpMyAdmin), and once they are completed, I will provide further instructions.

Update nu_send_welcome_email_template
(Fix template name)

Code: Select all

REPLACE
INTO `zzzzsys_php`(
    `zzzzsys_php_id`,
    `sph_code`,
    `sph_description`,
    `sph_group`,
    `sph_category`,
    `sph_status`,
    `sph_php`,
    `sph_run`,
    `sph_zzzzsys_form_id`,
    `sph_system`,
    `sph_global`,
    `sph_demo`,
    `sph_template`,
    `sph_hide`,
    `sph_json`
)
VALUES(
    'nu64f9c4ec5f59275',
    'nu_send_welcome_email_template',
    'Procedure is called when \"Send welcome email\" is checked in the user form',
    'nubuilder',
    'Email',
    '1',
    '// Retrieve Information about the user\r\n\r\n/*\r\n$userSavedInfo = nuUserSavedInfo();\r\n\r\n$userId = $userSavedInfo[\"user_id\"];\r\n$AccessLevelId = $userSavedInfo[\"access_level_id\"];\r\n$team = $userSavedInfo[\"team\"];\r\n$department = $userSavedInfo[\"department\"];\r\n$position = $userSavedInfo[\"position\"];\r\n\r\n$changePassword = $userSavedInfo[\"change_password\"]; // 1 = true, 0 = false\r\n$newUser = $userSavedInfo[\"new_user\"]; // 1 = true, 0 = false\r\n\r\n*/\r\n\r\n// Retrieve the template data (Template code, language, group)\r\n$template = nuGetEmailTemplateData(\"nu_send_welcome_email_template\", \'\', \'nubuilder\');\r\nif ($template == false) {\r\n nuDisplayError(\'Unknown email template!\');\r\n return;\r\n}\r\n\r\n$sendResult = sendEmailFromTemplate($template);\r\nif ($sendResult[0] != true) {\r\n nuDisplayError($sendResult[1].\'<br>\'.$sendResult[2]);\r\n}\r\n\r\n// Sends an email message using an email template.\r\nfunction sendEmailFromTemplate($template) {\r\n\r\n $body = str_replace(\'#\'.\'NUBUILDER_URL\'.\'#\', nuGetHttpOrigin() , $template[\'body\']);\r\n\r\n $params = array(\r\n \'to\' => $template[\'to\'],\r\n \'cc\' => $template[\'cc\'],\r\n \'bcc\' => $template[\'bcc\'],\r\n \'body\' => nl2br($body),\r\n \'subject\' => $template[\'subject\']\r\n );\r\n\r\n // Replace all Hash Cookies\r\n foreach ($params as $key => $value) {\r\n $params[$key] = nuReplaceHashVariables($value);\r\n }\r\n\r\n return nuSendEmail($params);\r\n\r\n}',
    'hide',
    '',
    '0',
    '1',
    '1',
    '1',
    '',
    NULL
)


Update User AS:
(Pass additional fields to the procedure)

Code: Select all

REPLACE
INTO `zzzzsys_php`(
    `zzzzsys_php_id`,
    `sph_code`,
    `sph_description`,
    `sph_group`,
    `sph_category`,
    `sph_status`,
    `sph_php`,
    `sph_run`,
    `sph_zzzzsys_form_id`,
    `sph_system`,
    `sph_global`,
    `sph_demo`,
    `sph_template`,
    `sph_hide`,
    `sph_json`
)
VALUES(
    'nuuser_AS',
    'nuuser_AS',
    'System PHP',
    'nubuilder',
    NULL,
    '1',
    '$changePassword = \'#sus_change_password#\' == \'1\';\r\n\r\nif (\'#check_password#\' != \'\') {\r\n\r\n $userId = \"#RECORD_ID#\";\r\n\r\n if ($_SESSION[\'nubuilder_session_data\'][\'USE_MD5_PASSWORD_HASH\'] != true) {\r\n $pw = nuPasswordHash(\'#check_password#\');\r\n } else {\r\n $pw = md5(\'#check_password#\');\r\n }\r\n\r\n nuRunQuery(\"UPDATE zzzzsys_user SET sus_login_password = \'$pw\' WHERE zzzzsys_user_id = ?\", [$userId]);\r\n\r\n nuSetUserJSONData(\'PASSWORD_CHANGED_TIME\', time(), $userId);\r\n\r\n if ($changePassword) {\r\n $expirationTime = time() + 3600;\r\n nuSetUserJSONData(\'OTP_EXPIRATION_TIME\', $expirationTime, $userId);\r\n }\r\n \r\n\r\n}\r\n\r\n\r\nfunction nuUserSavedInfo() {\r\n\r\n global $changePassword;\r\n\r\n return array(\r\n \'change_password\' => $changePassword,\r\n \'new_user\' => nuHasNewRecordID(),\r\n \'user_id\' => \'#RECORD_ID#\',\r\n \'access_level_id\' => \'#sus_zzzzsys_access_id#\',\r\n \'team\' => \'#sus_team#\',\r\n \'department\' => \'#sus_department#\',\r\n \'position\' => \'#sus_position#\' \r\n );\r\n\r\n}\r\n\r\nif (\'#user_send_welcome_email#\' == \'1\') {\r\n $result = nuRunProcedure(\'nu_send_welcome_email\');\r\n if ($result === false) {\r\n nuRunProcedure(\'nu_send_welcome_email_template\');\r\n }\r\n}',
    '',
    '',
    '1',
    '0',
    '1',
    '0',
    '',
    NULL
)
sietwolt
Posts: 47
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 9 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Running the sql update following message:
MySQL meldt: Documentatie
#1054 - Onbekende kolom 'sph_javascript' in INSERT INTO ( = unknown colum etc ..)
kev1n
nuBuilder Team
Posts: 4481
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 501 times
Contact:

Re: email template

Unread post by kev1n »

Run "Update nu_send_welcome_email_template" again, I made it compatible with versions < 9.2
sietwolt
Posts: 47
Joined: Sat Jan 11, 2025 10:50 am
Has thanked: 9 times
Been thanked: 1 time

Re: email template

Unread post by sietwolt »

Update User AS;
keeps error message : #1054 - Onbekende kolom 'sph_javascript' in INSERT INTO ( unknown colum ..)
Post Reply