Quotes and Tags in module parameters

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
rogerco
Joomla! Intern
Joomla! Intern
Posts: 95
Joined: Tue Jan 23, 2007 8:56 pm

Quotes and Tags in module parameters

Post by rogerco » Fri Aug 08, 2014 10:02 am

Tearing my hair out over this. I need to be able to save a string that is a fragment of html in a parameter (for a module, but I imagine it would be the same for a component)
So after much experimentation in the module xml I have:

Code: Select all

<field name='foo' type='text' size='40' default='<div style="position:relative;' label='foo Label' description='Foo description' />
Note I am using single quotes around the values here; that is legal xml and works ok. I've tried using double quotes in which case I can replace the " with a " but you can not include < in the string or the xml parser barfs.
So the default value for foo should be

Code: Select all

<div style="position:relative;
This works ok for installation and the default value is correctly displayed with the < and " chars in the module setup.
However when the module is saved the < (or <) is stripped off and a spurious extra 'matching' double quote is added at the end of the string.
So what you get back is

Code: Select all

div style="position:relative;"
The same happens if the default value is blank and you enter

Code: Select all

<div style="position:relative;
in the parameter field. It comes back without the < and with an extra " added on the end.
Help please: What syntax will allow parameters containing html tags and unmatched double quotes to be correctly saved?
Or will Joomla simply not allow html in parameters? And where is the spurious extra double quote at the end coming from - I don't want it.

Thans
RogerCO

User avatar
andypooz
Joomla! Guru
Joomla! Guru
Posts: 728
Joined: Sat Dec 30, 2006 3:03 pm
Location: London, UK
Contact:

Re: Quotes and Tags in module parameters

Post by andypooz » Fri Aug 08, 2014 10:24 am

How about

Code: Select all

default='\<div style=\'position:relative;'
Worth a shot?
If not, check the datatype of the parameter for the module you're using and see if you can change it to allow raw.
Andy
Andy Hickey
Bespoke Joomla Extension Developer
http://www.netamity.com

rogerco
Joomla! Intern
Joomla! Intern
Posts: 95
Joined: Tue Jan 23, 2007 8:56 pm

Re: Quotes and Tags in module parameters

Post by rogerco » Fri Aug 08, 2014 5:52 pm

Thanks Andy, but sadly not
Entering

Code: Select all

\<div style=\"display:table-row;
in the parameter value as you suggest once the module is installed returns

Code: Select all

\iv style=\"display:table-row;
so it has stripped off an extra character (the d as well as the <) - most odd, and the double quote doesn't get escaped - although it also doesn't get doubled.

I guess you can see this behaviour in any text parameter field for any module or component. If you enter a string containing a tag then when you save the parameters (Save and Close) and go back to reload them you will find that the < has been removed and if the string contains an odd number of quotes then an extra one is added at the end.

Escaping with a backslash doesn't work. It may be that this is deliberate as some subtle security effect. I could live without the < but having and extra quote added at the end of the string is a real pain.

Simplest way to see it is to put the string in the Note field which appears for all modules at the bottom right of the setup parameter. The adding of an extra quote only seems to happen if the string starts with <div or possibly any valid looking but incomplete tag.

RogerCO

mixahlos
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 132
Joined: Sat Jul 22, 2006 9:52 pm
Contact:

Re: Quotes and Tags in module parameters

Post by mixahlos » Thu Sep 04, 2014 7:04 pm

I have this in my xml file :

Code: Select all

<option value="myicon">MOD_MYMOD_MYMOD_ICON1</option>
and this in my language ini file :

Code: Select all

MOD_MYMOD_MYMOD_ICON1="<span class=\"icon-1\"><span class=\"icon-1-2\">"
and works fine for me
Mike


Locked

Return to “Joomla! 3.x Coding”