Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-08-13 14:45:52

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,963
Website GitHub

com_connect: How do I reliably detect being on a "thanks_form" page?

I have a signup form mid-way down a page with text above and below and the attribute thanks_form set to return a success message and a custom response, which is added to the com_connect_labels and com_connect_values arrays by a custom plugin after it has done its other work.

Everything works nicely, but when I successfully submit the form, the thanks message shows where the form was … mid-way down the page, which is easy to miss.

My question: Can I detect being on the successful submission “thanks_page” from within my article?

After some faffing around, I got the following working, which detects if the submit button field has been submitted, because that is stored as a $_POST variable, but it feels a little convoluted and looks like it would also match on a form error page.

<!-- get com_connect_submit $_POST variable from the "submit" button -->
<txp:variable name="form_is_submitted"><txp:page_url type="com_connect_submit" /></txp:variable>
<!-- if no submit button pressed -->
<txp:if_variable name="form_is_submitted" value="">

… Introductory text ...

</txp:if_variable>

<!-- the com_connect form -->
<txp:output_form form="signup_form" />

<!-- if no submit button pressed -->
<txp:if_variable name="form_is_submitted" value="">

... Further text …

</txp:if_variable>

In the process I learned that you get no output without having the com_connect form tag in place on the page, hence the “bracketing out” of the text above and text below the form, rather than an if…else at the top of the page.

PS: I did first tried using redirect="signupsection/" instead of thanks_form to redirect to another page (note: we need a trailing slash there for txp 4.9), but my custom added strings don’t come through. Not sure if the problem lies with com_connect or my plugin but my suspicion is that it is because there is no com_connect form on the redirected page to “accept” the values.


TXP Builders – finely-crafted code, design and txp

Offline

#2 Today 13:12:05

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,963
Website GitHub

Re: com_connect: How do I reliably detect being on a "thanks_form" page?

I guess this was too obscure / specific a question.

I’ll put it another way: is there any mileage in com_connect conveying the “success” or “error” state of a submitted form in a way that can be picked up on the following page?


TXP Builders – finely-crafted code, design and txp

Offline

#3 Today 13:39:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,853
Website GitHub

Re: com_connect: How do I reliably detect being on a "thanks_form" page?

Sorry, meant to reply. Short of testing $_POST (via ps()?) and having a com_connect tag on the receiving page to invoke the plugin, I can’t see a way of doing this cleanly at present.

We’re really stuck with having to have some tag on the receiving page or the plugin will remain dormant. Is there any way we can leverage com_connect_if on the destination page to pick up the URL hash or the presence of some POST variable? Even if it requires adding a mechanism for doing so to the plugin. It would be handy.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 Today 17:13:02

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,963
Website GitHub

Re: com_connect: How do I reliably detect being on a "thanks_form" page?

Bloke wrote #340191:

Short of testing $_POST (via ps()?) and having a com_connect tag on the receiving page to invoke the plugin, I can’t see a way of doing this cleanly at present.

Thanks. So what I am doing now currently does both – retrieves the $_POST variable of the submit button using <txp:page_url type="com_connect_submit" /> and maintains the com_connect tag on the page.

I presume this would also happen on a form submit error, hence my query of whether com_connect might be able to pass a success/fail-with-errors flag via com_connect_label/values. I just haven’t come across that situation yet as the on-page browser checks are better at ensuring details are complete.


TXP Builders – finely-crafted code, design and txp

Offline

#5 Today 17:24:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,853
Website GitHub

Re: com_connect: How do I reliably detect being on a "thanks_form" page?

jakob wrote #340196:

I presume this would also happen on a form submit error

If it redirects to the new page on error, yes it should. As you say, it’s difficult to test short of hacking the DOM in the Inspector, removing some browser-side validation limits and then submitting error-ridden values.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB