2

I'm trying to get a 3rd party livehelp to autofill with Joomla users name and email when logged in.

This is the js code to autofill:

LHCChatOptionsPage.attr_prefill = new Array();
LHCChatOptionsPage.attr_prefill.push({'name':'email','value':'[email protected]','hidden':true});
LHCChatOptionsPage.attr_prefill.push({'name':'username','value':'Username here'});

And this is the php code to get the variables from Joomla:

$user =& JFactory::getUser();
$user_name = $user->name; 
$user_email = $user->email;

But what do I need to do to use them together?

Any help would be much appreciated!

1 Answer 1

3

You can use addScriptDeclaration for this. With this function you can add JavaScript code to the <head> of your website.

<?php
$doc = JFactory::getDocument();
$user = JFactory::getUser();

$js = "LHCChatOptionsPage.attr_prefill = new Array();";
$js .= "LHCChatOptionsPage.attr_prefill.push({'name': 'email', 'value': '" . $user->email . "', 'hidden': true});";
$js .= "LHCChatOptionsPage.attr_prefill.push({'name': 'username', 'value': '" . $user->name . "'});"

$doc->addScriptDeclaration($js);
1
  • Hi and thanks! So as you say, this will add it to the <head> of the page But for this to work, I need the js code (prefill) to be with the rest of the js code that calls the livehelp. Many thanks if anyone can help? Commented Nov 19, 2015 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.