We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36549
    • 572 Posts
    Hi,
    I have been trying to change a chunk for FormIt on an existing site where the form had previously been working but has not been for a while.
    I upgraded to V2.5.7 and FormIt is V3.0.2 but I still can't make any changes to the chunk - it's just not saving. I have tried to create a new chunk but as soon as I add the formit code (even copied and pasted from a different site with working form) it looks like it's saving but doesn't.
    I get the following error in the logs:
    [2017-07-03 15:48:25] (ERROR @ /home/wwwmysite/public_html/core/components/syntaxchecker/syntaxchecker.class.php : 532) PHP warning: preg_replace(): Unknown modifier 'p'

    Anyone any ideas?

    This question has been answered by andytough. See the first response.

      www.9thwave.co.uk
         WEB | DESIGN | PRINT
    • discuss.answer
      • 38783
      • 571 Posts
      I would try disabling the Syntax Checker plugin referred to in the error log. I used to use it but occasionally had problems not being able to save stuff

      https://docs.modx.com/extras/revo/syntaxchecker
        If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

        email: [email protected] | website: https://andytough.com
        • 3749
        • 24,544 Posts
        Looking at the code, Syntax Checker uses a slash / as a delimiter for all its preg_replace operations. If you have a / on a part of the page that's analyzed by Syntax checker (especially one followed immediately by the letter 'p') it will throw that error because it will think the / is a closing delimiter and the p is modifier for the regex.

        One possible solution would be to have several possible delimiters and use strpos() to find one that's not in the string being analyzed.
          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
          • 36549
          • 572 Posts
          Thanks both for your suggestions.
          I have disabled the Syntax Checker Plugin and that has solved the issue.
          There is a </p> in the form content so that must be the trigger but it's valid syntax in this instance so not sure why the Plugin is throwing an error.
          Anyhow it is now working so thanks so much for your quick replies.
            www.9thwave.co.uk
               WEB | DESIGN | PRINT
            • 3749
            • 24,544 Posts
            It's not exactly the plugin, it's the PCRE engine that processes the regular expression used by the plugin. Regular expressions are patterns that the preg_match() function uses to search for matches. They need a delimiter at both ends of the pattern string. For example, '/[Hh]ello/' will search for the string 'hello' or 'Hello'. The engine will get confused when the delimiter occurs inside the pattern. Regex expressions can have a modifier at the end (following the closing delimiter) like this '/hello/i'. This will do a case-insensitive search for Hello, hello, HElLo, etc.

            This will work fine:

            $pattern = '/[Hh]ello/';
            $content = "<p>Hello</p>";
            preg_match ($pattern, $content , $matches);



            This code will *not* work fine:

            $pattern = '/<p>Hello</p>/';
            $content = "<p>Hello</p>";
            preg_match ($pattern, $content , $matches);


            When parsing the pattern, the engine will interpret the / in the middle as the end of the pattern and assume that the p following it is a modifier. Since there is no p modifier, it throws the error.

            That's why it's critical to select a delimiter that you're sure won't be in the pattern. This is difficult with MODX because @, #, ~, %, `, +, &, and /, could all occur in a MODX page. Selecting the delimiter dynamically after searching for it in the page would solve this.

            $delimiters = array(
            '@', '#', '%', // etc.
            }
            
            $delimiter = null;
            foreach ($delimiters as $d) {
               if (strpos($content, $d) === false) {
                  $delimiter = $d;
                  break;
               }
            }
            
            if ($delimiter !== null) {
               preg_match($delimiter . '[hH]ello' . $delimiter, $content, $matches);
            }


            I filed a bug report at GitHub for this, but I don't know if Everett is still maintaining the plugin.

            [update] The actual code uses preg_replace() not preg_match() but I used preg_match() (which throws the same error) in my examples for clarity. [ed. note: BobRay last edited this post 6 years, 9 months ago.]
              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