We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34174
    • 67 Posts
    I have a problem with radio buttons in a form (FormIt 2.2 / modx 2.2.6) displaying a php warning error

    in_array() [function.in-array]: Wrong datatype for second argument in /home/USERNAME/public_html/home/core/cache/includes/elements/modsnippet/41.include.cache.php


    The error shows up inside of every radio item. It seems this code produces the error:


    [[!+fi.property:FormItIsChecked=`No particular property`]]


    Any ideas on this? I tried clearing the cache and it doesnt help.

    Thanks.
      • 34174
      • 67 Posts
      Here are the contents of the snippet referred to (it is FormItIsChecked)

      <?php
      function elements_modsnippet_45($scriptProperties= array()) {
      global $modx;
      if (is_array($scriptProperties)) {
      extract($scriptProperties, EXTR_SKIP);
      }
      /**
       * FormIt
       *
       * Copyright 2009-2012 by Shaun McCormick <[email protected]>
       *
       * FormIt is free software; you can redistribute it and/or modify it
       * under the terms of the GNU General Public License as published by the Free
       * Software Foundation; either version 2 of the License, or (at your option) any
       * later version.
       *
       * FormIt is distributed in the hope that it will be useful, but WITHOUT ANY
       * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
       * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
       *
       * You should have received a copy of the GNU General Public License along with
       * FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
       * Suite 330, Boston, MA 02111-1307 USA
       *
       * @package formit
       */
      /**
       * Custom output filter that returns checked="checked" if the value is set
       *
       * @var string $input
       * @var string $options
       * @package formit
       */
      $output = ' ';
      if ($input == $options) {
          $output = ' checked="checked"';
      }
      $input = $modx->fromJSON($input);
      if (in_array($options,$input)) {
        $output = ' checked="checked"';
      }
      return $output;
      }
      
        • 34174
        • 67 Posts
        Well I have downgraded to Formit 2.1.2 and everything seems fine, so I guess something is up with 2.2. But someone else out there must be using formit 2.2 and also have radio buttons?
          • 3749
          • 24,544 Posts
          Here is some suspicious code in the core:

          public function fromJSON($src, $asArray= true) {
                  $decoded= '';
                  if ($src) {
                      if (!function_exists('json_decode')) {
                          if (@ include_once (XPDO_CORE_PATH . 'json/JSON.php')) {
                              if ($asArray) {
                                  $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
                              } else {
                              $json = new Services_JSON();
                              }
                              $decoded= $json->decode($src);
                              }
                      } else {
                          $decoded= json_decode($src, $asArray);
                      }
                  }
                  return $decoded;
              }


          function json_decode ($json, $assoc = false, $depth = 512, $options = 0) {}


          It looks like if json_decode() exists, you'll get nothing, but maybe I'm missing something.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            json_decode is a PHP function if the JSON handling libraries are part of the PHP installation. Versions before 5.2-something may not have it; it wasn't included by default until then, and it's still possible to configure PHP without it. http://www.php.net/manual/en/json.installation.php
              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
              • 3749
              • 24,544 Posts
              The place I found it is an abstract class, so it should never execute, but I can't find any real version of it for use on systems without the PHP function.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 34174
                • 67 Posts
                Folks, thanks for the responses. The server is on PHP 5.2.17, but there should be some kind of fallback if json_decode is not available. Sticking with FormIt 2.1.2 for now.
                  • 3749
                  • 24,544 Posts
                  John, I was just guessing at the problem. It could be something unrelated to json_decode().
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 34174
                    • 67 Posts
                    Has to be something in the fromJSON function. Its the only difference between the FormItIsChecked snippets for FormIt 2.2 and FormIt 2.1.2
                      • 3749
                      • 24,544 Posts
                      It look like that's it: https://github.com/splittingred/FormIt/commit/0aa9cc5ce2906c2329a6e31f13fc94cd46e03899.


                      The earlier version is not using fromJSON() at all.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting