We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49407
    • 159 Posts
    Quote from: sottwell at Jan 07, 2015, 07:45 AM
    The form is output after the formit snippet is run. Using the placeholder as a formit property means that the value must be available before the formit snippet is run. If a formit processor is creating the placeholder, then it cannot be available before the formit snippet, and its processor, is run.

    I understand what you are saying, however the PREprocessor is setting the grow.id placeholder. In fact I have tried to replace the placeholder in the formit call parameter with $_GET['gid'] and it still fails to process it. And that is in the http header, set well before the formit call is processed.
      • 49407
      • 159 Posts
      Quote from: sottwell at Jan 07, 2015, 08:03 AM
      A pre-processor is not running before formit itself. It is run before the form is submitted, yes, which is why the formit snippet comes before the form so that any placeholders it sets can be used, but it's still processed inside of formit. The formit snippet is run on every page load, including the first one. How it behaves depends on whether there is an appropriate POST for it to process, what post-processors it has, and what pre-processors it has. But it can't use a placeholder as a property that's only generated after it's already loaded its properties and started running.

      I'm using a standalone preprocessor snippet that is being loaded before formit. I'm not using formit's preprocessor.
        • 49407
        • 159 Posts
        I'm using FormIt 2.2.0-pl version if that helps trouble shoot. Also my MODX Revo version is 2.3.2-pl
          • 49407
          • 159 Posts
          This is the fihooks class from formit.

          To me this looks like it's not accepting placeholders correctly...

              /**
               * Redirect to a specified URL.
               *
               * Properties needed:
               * - redirectTo - the ID of the Resource to redirect to.
               *
               * @param array $fields An array of cleaned POST fields
               * @return boolean False if unsuccessful.
               */
              public function redirect(array $fields = array()) {
                  if (empty($this->formit->config['redirectTo'])) return false;
                  $redirectParams = !empty($this->formit->config['redirectParams']) ? $this->formit->config['redirectParams'] : '';
                  if (!empty($redirectParams)) {
                      $prefix = $this->modx->getOption('placeholderPrefix',$this->formit->config,'fi.');
                      $this->modx->setPlaceholders($fields,$prefix);
                      $this->modx->parser->processElementTags('',$redirectParams,true,true);
                      $redirectParams = $this->modx->fromJSON($redirectParams);
                      if (empty($redirectParams)) $redirectParams = '';
                  }
                  $contextKey = $this->modx->context->get('key');
                  $resource = $this->modx->getObject('modResource',$this->formit->config['redirectTo']);
                  if ($resource) {
                      $contextKey = $resource->get('context_key');
                  }
                  $url = $this->modx->makeUrl($this->formit->config['redirectTo'],$contextKey,$redirectParams,'full');
                  $this->setRedirectUrl($url);
                  return true;
              }
          


          I don't know how the parser works enough to say for sure but something just doesn't look right. Maybe Shaun McCormick could chime in here and give some insight?
            • 49407
            • 159 Posts
            Quote from: sottwell at Jan 07, 2015, 09:19 AM
            In the snippet itself, when instantiating the formit object:
            $fi = new FormIt($modx,$scriptProperties);

            And in the constructor of the FormIt object
            function __construct(modX &$modx,array $config = array())

            So the snippet passes its properties to the object. That means the property has to be available at the time the snippet loads the object.

            $this->formit->config['redirectTo']

            I don't think you are understanding what I'm saying...

            Here is an ordered list of my code:

            1. saveChroniclePreProcessor is called. - This sets the placeholders required for the form and the FormIt parameter.
            2. I am outputting the contents of [[!+grow.id]] to check that it is set. It is. It outputs the correct id.
            3. Calling FormIt, attempting to set redirectParams with [[!+grow.id]] that is already set and output prior to the FormIt call.
            4. The form is output with all the placholders set by saveChroniclePreProcessor. All the fields are filled correctly.
            5. When the form is submitted, saveChronicleProcessor is called via FormIt hook. The placeholder [[!+grow.id]] does not get parsed by line 300 in core/components/formit/model/formit/fihooks.class.php

            What you are saying is, FormIt is being instantiated prior to saveChroniclePreProcessor is being ran. If this is true then that means MODX is ignoring the order in which I write my code and favoring FormIt to be instantiated before my other snippet saveChroniclePreProcessor even though I am calling saveChroniclePreProcessor first.

            So which is it? Line 300 in core/components/formit/model/formit/fihooks.class.php failing to parse correctly or MODX processing snippet calls in the wrong order?
              • 3749
              • 24,544 Posts
              It's a little tricky, but you can set up a good editor to let you debug the MODX code as it's running. IOW, you can run the code, line by line, and watch the values of every variable at every point. With luck, you could put a breakpoint in the saveChronical code and step a line at a time from there.

              You can see the MODX placeholders and $scriptProperties arrays and you can trace right into FormIt.

              It can be extremely time-consuming, but it's pretty much guaranteed to show you what's happening if you keep at it. Sometimes, there's nothing else you can do.
                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
                • 49407
                • 159 Posts
                Quote from: sottwell at Jan 09, 2015, 07:03 AM
                saveChroniclePreProcessor is a separate snippet that you have in your HTML before the FormIt snippet? Or is it a FormIt preHook?

                If it's a FormIt preHook, then FormIt has to be running, with its properties available to it in its 'config' array, in order to know what code (.php file or snippet) to run as a preHook.
                $this->formit->loadHooks('pre',$this->config);


                So a preHook cannot provide a value for a FormIt property, which properties have to already be available in order to run the preHook.

                Yes, I've said it before, saveChroniclePreProcessor is a separate snippet that I have in my HTML before the FormIt snippet.

                I put a band-aid on the problem by writing a new post processor that redirects using the form field grow_id, however, I want to know why the parser is failing to parse the placeholder. This could be a serious core bug or it could just be the way FormIt is using the parse method at line 300 in core/components/formit/model/formit/fihooks.class.php



                Quote from: BobRay at Jan 09, 2015, 05:53 AM
                It's a little tricky, but you can set up a good editor to let you debug the MODX code as it's running. IOW, you can run the code, line by line, and watch the values of every variable at every point. With luck, you could put a breakpoint in the saveChronical code and step a line at a time from there.

                You can see the MODX placeholders and $scriptProperties arrays and you can trace right into FormIt.

                It can be extremely time-consuming, but it's pretty much guaranteed to show you what's happening if you keep at it. Sometimes, there's nothing else you can do.

                I started tracing on this bug and as far as I got was to the parse method and it appears that $this->modx->parser->processElementTags('',$redirectParams,true,true); is not parsing the placeholder correctly. I don't know enough about that method enough yet to say why it fails or if it's invoked incorrectly or something else is wrong but I will use the band-aid I made till I get free time to do deeper tracing as you describe.

                UPDATE: At this point I know that prior to $this->modx->parser->processElementTags('',$redirectParams,true,true); the value of $redirectParams is '{"id":"[[!+grow.id]]"}' and after the parser runs the value of $redirectParams is '{"id":""}'.

                Bob, could you give me an example of what you mean by out-puting the placeholder at the moment before line 300 runs in fihooks.class.php. I know how to retrieve stuff from the $scriptProperties array but I don't know how to check contents of placeholders while in PHP. [ed. note: aaronkent last edited this post 9 years, 3 months ago.]
                • Quote from: aaronkent at Jan 09, 2015, 07:20 AM
                  saveChroniclePreProcessor is a separate snippet that I have in my HTML before the FormIt snippet.

                  Is there a special reason to do that outside of FormIt? You could create a FormIt preHook that fills your value inside of FormIt. You don't have to watch when which placeholder is set and when which placeholder tag is replaced this way.
                  • Yes, I've said it before, saveChroniclePreProcessor is a separate snippet that I have in my HTML before the FormIt snippet.
                    Sorry, I missed that point.
                      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
                      IIRC, when you reach that point in the debugger, all set placeholders should be in $modx->placeholders.

                      I meant to ask, is your FormIt tag in a chunk? If so, that could be the problem.
                        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