I have the html below; in Joomla email addresses appear on your website obfuscated, or ‘cloaked’. I have been using this to display email addresses on my website, JHtml::_(’email.cloak’, ‘demo@example.com’). But I can’t seem to display an email address in an input text field.
<input id="email_field" name="email" placeholder="<?php echo JHtml::_('email.cloak',$result->email_address, 0); ?>" type="text" />
Using the code above will generate the following script in the input field..
<script type='text/javascript'>
<!-- var prefix = 'ma' + 'il' + 'to';
var path = 'hr' + 'ef' + '=';
var addy16915 = 'user' + '@';
addy16915 = addy16915 + 'user' + '.' + 'com';
document.write(addy16915); //-->\n
</script>
<script type='text/javascript'>
<!-- document.write('<span style=\'display: none;\'>'); //-->
</script>
This email address is being protected from spambots. You need JavaScript enabled to view it.
<script type='text/javascript'>
<!-- document.write('</'); document.write('span>'); //-->
</script>
Any ideas? Thanks
JHtmlEmail::cloak can only write document text, it can not write in element attributes as in your case. If you really need this you would have to create your own JHtml helper. This could be accomplished by the steps below.
Implementing a Joomla function for cloaking emails in attributes:
Create the helper class at your_components/helpers/html/specialemail.php:
Then write your input email element like:
It uses the same cloak algorithm as the original Joomla cloak function. Instead of using
document.writeto output the email to the document, it uses a snippet from this answer to decode the ASCII entities and then sets the value to the chosen attribute directly.