Skip Navigation

[Resolved] wpv-conditional: How to check Form ID value inside URL Parameter

This thread is resolved. Here is a description of the problem and solution.

Problem:

Use option "After visitors submit this form: Keep displaying this form" in post form, Why is _1 added to my form inside the parameter? Is this always the case, or would it ever be different? How can I best refer to a specific form ID inside the URL parameter?

Solution:

The _1 is form instance number, for example if you are displaying same post form(ID 3351) in same page multiple times, you will get multiple instances post form(ID 3351), you will get different URL parameters: 3351_1, 3351_2 ...

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by GamX 4 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1721247

Hello, can you explain how Form IDs work inside a URL parameter? Specifically:
(1) Why is _1 added to my form inside the parameter? Is this always the case, or would it ever be different? How can I best refer to a specific form ID inside the URL parameter?
(2) I want to use form ID as part of a conditional statement so I can test for different forms on the page being submitted or not, rather than just testing for the submission of any form. How should I do this?

CONDITIONAL DISPLAY - THIS WORKS
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '')"]
This is what I see the first time visiting the page (before submitting a form), or if I click on a direct link to the page.
[cred_user_form form='my-user-form']
[/wpv-conditional]

[wpv-conditional if="('[wpv-search-term param="_success"]' NE '')"]
This is what I see after submitting a form on the page.
[/wpv-conditional]

CONDITIONAL DISPLAY - HOW TO SPECIFY FORM ID INSTEAD?
Instead of the above example, if I want to test for a specific form ID, it looks like I have to add _1 after the form ID.

THIS DOES NOT WORK
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '3151')"]
I have just submitted form #3151 (this number is the value of the URL parameter called _success)
[/wpv-conditional]

THIS WORKS - BUT WHY?
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '3151_1')"]
I have just submitted form #3151_1 (this number is the value of the URL parameter called _success)
[/wpv-conditional]

TWO FORMS ON ONE PAGE - CAN I USE CONDITIONAL STATEMENTS TO CHECK FOR WHICH WAS JUST SUBMITTED?
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '')"]
I have not yet submitted any forms on the page
[/wpv-conditional]
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '3151_1')"]
I have just submitted the 1st form on the page, Form #3151_1
[/wpv-conditional]
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '4207_1')"]
I have just submitted the 2nd form on the page, Form #4207_1
[/wpv-conditional]

#1721455

Hello,

Which form are we talking about?
Are they Toolset Forms for creating posts or custom search form of Toolset Views/Blocks?

If they are Toolset Forms for creating posts, after user submit those form, redirect to target page, there will be an URL parameter "cred_referrer_form_id", it's value is your post form ID.
You can get it's value with shortcode [wpv-search-term param="cred_referrer_form_id"]

And use above shortcode like this:

[wpv-conditional if="('[wpv-search-term param="cred_referrer_form_id"]' eq '3151')"]
I have just submitted the a form on the page, Form #3151
[/wpv-conditional]
#1723183

Hi, I am talking about User Forms that a User submits. The user is not creating posts. Rather they are taking an online course, and my User forms contain User fields that the User submits values for. These values are used to personalize the course in various ways.

Is the cred_referrer_form_id parameter the right one to use in this case?

Also please clarify where to insert the above code. I added it to the website's page where I want to display the conditional content, not within Toolset's "Edit User Form" area.

In case it's helpful, here is the URL I see after submitting form #3151 on one of my pages:
hidden link

#1723401

I assume your are using option "After visitors submit this form: Keep displaying this form" in your user form.

If it is, in the URL you mentioned above, the URL parameter "_success" is the form ID + instance ID, so you can setup the codes like this:

[wpv-conditional if="( '[wpv-search-term param="_success"]' eq '3351_1' )"]
 It is form 3351 submitted!
 [/wpv-conditional]
#1724025

Thank you! That seems to work when there is a single form on the page! A few follow up questions...

1) Yes, I am using the "keep displaying this form" option but may not need it. Would the above solution work either way?

2) Why is the _1 appended to the end of the form ID? Will this always be the case? I'm happy to test for the URL value each time I design a page, but want to make sure it will do the same thing every time for users with different browsers, etc.

3) I tested having two sequential forms on the same page. I use wpv-conditional to display the first form when you first visit the page (param value of null). Then after you submit the first form (param value now includes the form ID of the submitted form plus the _1), the wpv-conditional statement says to only show the second form. Then I show some conditionally displayed results including some of the values submitted. But when the second form is submitted the URL is now:
hidden link

So now the search parameter is cred_user_form_2658_1. Again, would this always be the case with a second form that I can use reliably?

4) Is there a "contains" or "includes" argument instead of "equals" that I could use, so that I could simply check for the 2658 instead of the varieties above?

#1725281

1) If you are using other options, you can try the codes I provided above:
https://toolset.com/forums/topic/wpv-conditional-how-to-check-form-id-value-inside-url-parameter/#post-1721455

2) The _1 is form instance number, for example if you are displaying same post form(ID 3351) same page multiple times, you will get multiple instances post form(ID 3351), you will get different URL parameters: 3351_1, 3351_2 ...

3) Yes, it is reliably to use URL parameter value "cred_user_form_2658_1" in your case.

4) No, there isn't such kind of feature within shortcode [wpv-conditional], see our document:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

But you can create your own custom shortcode to check if the URL parameter contains specific number, then use it in [wpv-conditional] shortcode, see our document:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-custom-shortcodes
section "Checking Custom shortcodes"

#1727757

My issue isn't yet resolved, but I'm confident it will be when I apply this info.