We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8991
    • 2 Posts
    Hi Guys,
    I’m trying to develop a suite of snippets to make it easy for clients to post new content from the web. I’m doing well it seems, but there’s a select box i use that lets them select related articles. However, when I name the selectbox with the [] at the end, I get a parse error:

    PHP error debug
      Error: 	htmlspecialchars() expects parameter 1 to be string, array given	 
      Error type/ Nr.: 	Warning - 2	 
      File: 	/home/www/orangesparkleball.com/manager/includes/document.parser.class.inc.php(769) : eval()'d code	 
      Line: 	155
    


    When I take off the brackets from the field name, the error stops, but I only get one value from the select box, instead of all selected options.

    I’m grateful for any help.

    The code I use is very simple:
    $related = implode(',',$_POST['related_articles']);
    


    Thanks!
    Eric
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You would have to make a foreach loop to run the htmlspecialchars function on each value.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 10449
        • 956 Posts
        You can just as well use array_map:

        $cities = array_map(’htmlspecialchars’, $_POST[’cities’]);

        Also, I prefer using serialize() for storing arrays into a DB-table and unserialize() to get it back out of it.