In Joomla 4.3.4 I have created a menu item Create Article for a specific category. When I try to create a new Article and enter the edit view, I get the following error:

0 htmlspecialchars(): Argument #1 ($string) must be of type string, array given

This does not happen when editing existing articles. The call stack looks like this:

#   Function    Location
1   ()  JROOT/administrator/components/com_categories/layouts/joomla/form/field/categoryedit.php:103
2   htmlspecialchars()  JROOT/administrator/components/com_categories/layouts/joomla/form/field/categoryedit.php:103
3   include()   JROOT/libraries/src/Layout/FileLayout.php:128
4   Joomla\CMS\Layout\FileLayout->render()  JROOT/administrator/components/com_categories/src/Field/CategoryeditField.php:369
5   Joomla\Component\Categories\Administrator\Field\CategoryeditField->getInput()   JROOT/libraries/src/Form/FormField.php:1029
6   Joomla\CMS\Form\FormField->renderField()    JROOT/libraries/src/Form/Form.php:536
7   Joomla\CMS\Form\Form->renderField() JROOT/components/com_content/tmpl/form/edit.php:106
8   include()   JROOT/libraries/src/MVC/View/HtmlView.php:410
9   Joomla\CMS\MVC\View\HtmlView->loadTemplate()    JROOT/libraries/src/MVC/View/HtmlView.php:203
10  Joomla\CMS\MVC\View\HtmlView->display() JROOT/components/com_content/src/View/Form/HtmlView.php:197
11  Joomla\Component\Content\Site\View\Form\HtmlView->display() JROOT/libraries/src/MVC/Controller/BaseController.php:645
12  Joomla\CMS\MVC\Controller\BaseController->display() JROOT/components/com_content/src/Controller/DisplayController.php:121
13  Joomla\Component\Content\Site\Controller\DisplayController->display()   JROOT/libraries/src/MVC/Controller/BaseController.php:678
14  Joomla\CMS\MVC\Controller\BaseController->execute() JROOT/libraries/src/Dispatcher/ComponentDispatcher.php:143
15  Joomla\CMS\Dispatcher\ComponentDispatcher->dispatch()   JROOT/components/com_content/src/Dispatcher/Dispatcher.php:56
16  Joomla\Component\Content\Site\Dispatcher\Dispatcher->dispatch() JROOT/libraries/src/Component/ComponentHelper.php:361
17  Joomla\CMS\Component\ComponentHelper::renderComponent() JROOT/libraries/src/Application/SiteApplication.php:208
18  Joomla\CMS\Application\SiteApplication->dispatch()  JROOT/libraries/src/Application/SiteApplication.php:249
19  Joomla\CMS\Application\SiteApplication->doExecute() JROOT/libraries/src/Application/CMSApplication.php:293
20  Joomla\CMS\Application\CMSApplication->execute()    JROOT/includes/app.php:61
21  require_once()  JROOT/index.php:32

The code around line 103 of administrator/components/com_categories/layouts/joomla/form/field/categoryedit.php is as follows:

 94    if ($multiple && is_array($value)) {
 95        if (!count($value)) {
 96            $value[] = '';
 97        }
 99       foreach ($value as $val) {
100            $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($val, ENT_COMPAT, 'UTF-8') . '">';
101        }
102    } else {
103        $html[] = '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value , ENT_COMPAT, 'UTF-8') . '">';
104    }```

What am I missing?
  • Could you provide details of the data of the category and menuitem, and any other data which is different from default joomla configuration? If this is pure out-of-the-box joomla (with no extensions added) then it maybe indicates a bug. I've tried configurating a front-end form menuitem for creating an article with a specific category and it works ok and I don't get any errors. Aug 24 at 22:56
  • It is a fairly large Joomla project migrated from Joomla 3 with quite a lot of extensions using custom fields. As far as I understand, line 103 should deal with this error. How can I debug this error?
    – cappu
    Aug 25 at 8:27
  • I just edited the question to be more specific about when the error actually occurs.
    – cappu
    Aug 25 at 8:33

1 Answer 1


In line #103 you have passed $value to htmlspecialcharacters after you have set $value as an array earlier, before line #94 or at #96.

htmlspecialcharacters is expecting a string, not an array, as the first argument.


To be executing line #103 you have failed to meet the condition on #94, $multiple is True and $value is an array. The error message says that $value is an array therefore $multiple must be false.

I attempted to recreate your described scenario of creating a menu item to create an article and I can confirm $multiple is false by default but I can't cause the message because $value is a string and not an array.

The $multiple is set by a field in the .xml file for the form or custom field that has the attribute of multiple="true" and for $value to be an array then the field is probably a drop down list or checkbox field type with more than one value that can be set.

Given I can't recreate the error with a standard Joomla install then is it possible you have custom field(s) added to the category or article or an override of the article/category form that has a new or modified field that is missing a multiple="true" statement?

  • 1
    Yes, but this is core Joomla code, not extension code. Aug 25 at 7:41
  • @Irata Your answer helped me a lot and I was able to solve the problem - somehow. In my Joomla setup there were also Custom Fields defined for Categories. Each Custom Field definition was assigned to "All Categories". By assigning the Custom Fields to only some of the categories, the error that occurred with the Custom Fields for Articles seemed to go away and I can no longer replicate it.
    – cappu
    Aug 26 at 10:08

Your Answer

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

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