retaining HTML string from POST

62 views
Skip to first unread message

ALFsoft

unread,
Jun 10, 2018, 9:26:56 AM6/10/18
to 'Hannes Papenberg' via Joomla! General Development
Hi Guys,

I’m sure I’m missing something very basic here, but I’ve been staring at it for a while now and I can’t seem to solve it.

I’m sending a HTML String (form data) via POST, the header info seems to be OK:


However, when I retrieve the string all HTML tags see to get lost and I end up with plain text…

The code I have is:
// Get the data from the form.
$data    = $input->get('jform', array(), 'post', 'array');
$message = $data['message'];

Now $message only contains plain text.
How do I retain the HTML string?

Groeten,
Alfred

Viper

unread,
Jun 10, 2018, 10:55:43 AM6/10/18
to Joomla! General Development
All array values will be cleaned with the default JFilter::clean(). Default value is 'string' - a fully decoded and sanitised string.
https://github.com/joomla/joomla-cms/blob/staging/libraries/src/Filter/InputFilter.php#L125

Yves

unread,
Jun 11, 2018, 7:30:40 AM6/11/18
to Joomla! General Development
Hi Alfred !

In your XML form definition file you can add the "filter" attribute with the  value "safehtml" (safer) or "raw" (completely unfiltered).

Example :

        <field
            name="message"
            type="textarea"
            filter="raw"
            required="true"
            label="COM_YOUCOMP_FORM_LBL_MESSAGE"
            description=" COM_YOUCOMP_FORM_DEC_ MESSAGE "
            hint=" COM_YOUCOMP_FORM_TOOLTIP_MESSAGE"/>

And this article on retrieving data with JInput : https://docs.joomla.org/Retrieving_request_data_using_JInput

HIH

Yves

ALFsoft

unread,
Jun 11, 2018, 7:42:36 AM6/11/18
to joomla-de...@googlegroups.com
@Yves
The filter in my XML definitief was already on ‘safehtml’ .

@Victor
Thanks for pointing me towards a working solution, I now have working code:

$input = JFactory::getApplication()->input;

$dataArray = $input->getArray(array(
‘Jform’ => array(
‘subject’ = string,
‘Message ‘ = raw
)
));

$data = $dataArray[‘jform’];
$subject = $data[‘subject’];
$message = $data[‘message’];

Now $message contains the correct HTML string.

Met vriendelijke groeten,
Alfred
--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages