<![CDATA[ FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible? - My Forums]]> https://forums.modx.com/thread/?thread=95657 <![CDATA[FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=3#dis-post-517775
[[!FormIt?
    &hooks=`saveChronicleProcessor,redirect`
    &redirectTo=`15`
    &redirectParams=`{"id":"[[!+grow.id]]"}` // <------ The placeholder isn't setting the parameter, it stays blank.
    &validate=`
        day:required:isNumber,
        week:required:isNumber,
        summary:required:minLength=^50^,
        content:required,
        publish_on:isDate,`
]]
[[!+grow.id]] // <----- This line here is being output as expected.


The placeholder is outputting outside of the FormIt.redirectParameter, but not inside it.

The url looks like this; "http://cannacle.com/dashboard/view-grow?id="

Where is the placeholder wandering off to inside FormIt?]]>
aaronkent Dec 31, 2014, 04:41 PM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=3#dis-post-517775
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=3#dis-post-559731
[[!+grow.id]]
]]>
BobRay Jul 19, 2018, 11:09 PM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=3#dis-post-559731
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=3#dis-post-559706 https://forums.modx.com/thread/101938/formit-dynamic-redirect#dis-post-549639

Now it works.]]>
Serifenlos Jul 19, 2018, 11:03 AM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=3#dis-post-559706
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible? (Best Answer)]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518170
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":""}'.

This means, the placeholder wasn't set by your snippet at this point, for some reason.
I dont't think, its a failure of the parser.]]>
Bruno17 Jan 09, 2015, 05:02 AM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518170
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518164
I meant to ask, is your FormIt tag in a chunk? If so, that could be the problem.]]>
BobRay Jan 09, 2015, 02:53 AM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518164
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518161 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.]]> sottwell Jan 09, 2015, 01:45 AM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518161 <![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518160 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.]]>
Jako Jan 09, 2015, 01:34 AM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518160
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518159 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.]]>
aaronkent Jan 09, 2015, 01:20 AM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518159
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518150
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.]]>
BobRay Jan 08, 2015, 11:53 PM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518150
<![CDATA[Re: FormIt: Setting the redirectParams dynamically with a placeholder. Is it possible?]]> https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518141 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?]]>
aaronkent Jan 08, 2015, 06:24 PM https://forums.modx.com/thread/95657/formit-setting-the-redirectparams-dynamically-with-a-placeholder-is-it-possible?page=2#dis-post-518141