We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36565
    • 73 Posts
    Hey guys,

    I have a page with a FormIt form on it. I have some JS to set the value of a form element, and I think that the value really is correctly set, because DOM inspection tools show the desired value with respect to the form element.

    When I inspect the page's source code at the same time, however, the supposedly injected value doesn't show up, and my attempt to get the value for post-submit processing with the FormIt hook fails.

    Why is that?
    Thanks a lot!

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

      PHP illiterate MODx enthusiast
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The page source code shows what got loaded initially, and the value wasn't loaded until later via javascript.

      Try just putting an echo of the $_POST in the hook, and see what is getting submitted.

      echo "<pre>";
      print_r($_POST);
      echo "</pre>";


        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
        • 36565
        • 73 Posts
        Yeah, that really seems to be the case. Note, though, that I can't just put the echo(); into the hook as it doesn't output anything. There is the possibility of using MODx's log, but putting print_r($_POST) into the log just outputs '1'.

        In any case, it seems I have to somehow make FormIt realize the newly loaded value.
        What would I have to do to reach that goal?

        Thanks again! It is much learning when you're new to something, so I appreciate your patience smiley
          PHP illiterate MODx enthusiast
        • discuss.answer
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It should accept the value, if the javascript is setting a value. Maybe you can just use a resource with a snippet to read back the POST as the action of the form, to make sure that it is indeed getting set.
            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
            • 36565
            • 73 Posts
            Thanks! I succeeded in having "print_r($_POST)" in a snippet that I used as FormIt hook.

            I stumbled into something - potentially revealing. There is no value for the field I tried to set at all, but then, there isn't even the corresponding key! Can it be that...

            ...

            an input of type "button" does not add a field to the form it is used in, while an input of type "submit" does?
              PHP illiterate MODx enthusiast
              • 36565
              • 73 Posts
              That was it!
              Thanks for the assistance, Susan!

              I am not going to try to carry form data from an input of type button again...
              Cheers!
                PHP illiterate MODx enthusiast