MODX Community

Debugging Formit, Redirect and FormitRetriever

I’ve a strange Formit problem. Obviousyl I have a form Pre and post hooks are being processed correctly but the redirect doesn’t work and the Formretriever snippet gets no data.

Have tried the redirect without any other post hook except redirect with a published resource and I’m just bounced back to the form. Tried that both with and without the formretriever snippet on the destination resource so it’s not simply that the formitretrieer is redirecting when it can’t find any data.

Has anyone any suggestions on a systematic way of debugging this?

1 Like

I should stress here that the resulting page is simply the original form page but it has received the POST data as other hooks run fine. And also, I have other formit calls with redirects on the same domain - well, actually a subdomain, perfectly.

1 Like

Is your redirect page possibly not published?

Please could you post the code for your form.

1 Like

As I say in the original post - I’m redirecting to a published resource - or trying to…

1 Like

Andy, I don’t believe the form is the issue as the hooks are being processed correctly with all form fields available from the $hook object. Some portions of it are generated on the fly so I’m not sure posting it here would help either.

I ended up using a hook to throw the result of $hook->getValues into a session object and then do the redirect to my final resource where I retrieve the form data from the session object which solves the issue but I’d still like to know why formit itself could not redirect.

I’d specifically like to hear from anyone familiar with the cache setting mechanism as that seems the likely suspect for investigation.

1 Like

showing code is allways helpfull. Be it only to understand, what you are trying

2 Likes

Normally I would agree but I don’t see how code I’ve written helps in this case. My formit call is syntactically correct, my form is also correct. All of my hooks are functioning flawlessly but even when I don’t use any hook except the redirect one, the redirect doesn’t happen.

As this is on a subdomain which is set up as a different context to the main site, I suspect it may be an issue with the cache handling as I believe the cache is stored under the context key and I don’t see that being created in my case. This is why I was looking for someone familiar with the code base to point me in the right direction. I’ve spent significant time already ensuring everything else is correct - the code you all want to see.

1 Like

Regarding the cache, I should also mention that I tried setting the storeLocation property to session on both the formit and formitretriever calls without any change.

1 Like

It sounds like it may be silent failing on a Hook. Have you tried taking the hook list down to the “redirect” and building it back up from there to see which it fails on?

1 Like

I explicitly say in the first post that I tried it using just the redirect.

1 Like

I apologize, I read that backwards. Have you tried setting the resource to be uncached? Sometimes other plugins affect the caching and performance of the hooks. Additionally, what are the pre/post hooks that do work?

1 Like

No worries. Nothing is cached, The formretriever snippet sits directly in the content, i.e. it’s not in a chunk, it’s called in an uncached resource - I added some debug code to the fromitretriever snippet to confirm that it can’t retrieve the data from Formit’s ‘store’. I did discover the redirect wasn’t working because the form’s URL was the same URL that Formit was redirecting to when it couldn’t find the data in the store so it seems the redirect isn’t the issue. just the store.

My workaround is functioning fine for this for now. If I have a chance I’ll come back and dig into it more to see why the store isn’t being set. It’s just strange because the store for another formit driven form which is very similar in the same context works flawlessly. If it was both forms I’d put it down to some dodgy context setting.

1 Like