Skip Navigation

[Resolved] Using option value from Formidable form field as conditional

This support ticket is created 6 years, 3 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 11 replies, has 2 voices.

Last updated by hugoC-5 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1152140

Tell us what you are trying to do?
I created a form with Formidable Pro containing a multiple choice field with separate values, like this:
labels:option 1, option 2, option 3
values: green, yellow, blue

I have put his field under Types control.

I also have a list of posts tagged with green, yellow or blue.

Now I would like to add a list of relevant posts to the result page containing a Formidable view:
If a user checked option 1 he should see all posts tagged with green.
If a user checked options 2 and 3 he should see all posts tagged with yellow or blue.

So I created this view:

<wpv-loop wrap="3" pad="true">
[wpv-item index=1]
<tr>
<td>
[wpv-conditional if="( $(wpcf-selectievakje).id(frm_display) eq 'talenten' )"][wpv-post-body view_template="Loop item in Berichten volgens tag"][/wpv-conditional]
</td>
[wpv-item index=other]
<td>
[wpv-conditional if="( $(wpcf-selectievakje).id(frm_display) eq 'talenten' )"][wpv-post-body view_template="Loop item in Berichten volgens tag"][/wpv-conditional]
</td>
[wpv-item index=3]
<td>
[wpv-conditional if="( $(wpcf-selectievakje).id(frm_display) eq 'talenten' )"][wpv-post-body view_template="Loop item in Berichten volgens tag"][/wpv-conditional]
</td>
</tr>
[wpv-item index=pad]
<td></td>
[wpv-item index=pad-last]
<td></td>
</tr>
</wpv-loop>

Where "selectievakje" is the Formidable form field and "Talenten" is an option value.
In order to make this work I suppose I need to retrieve the form result, but I can't get this to work so far.
Can you help?

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/#checking-radio-fields-values

#1152656
Screen Shot 2018-11-25 at 12.18.36 PM.png

Now I would like to add a list of relevant posts to the result page containing a Formidable view:
If a user checked option 1 he should see all posts tagged with green.
If a user checked options 2 and 3 he should see all posts tagged with yellow or blue.

I would not use conditional HTML here, because it could cause problems with the table structure. If the Formidable Form redirects the User to a URL with parameters for each selection, you can simply use a Query Filter. Let's say the Form redirects to a URL like this if the User selects Option 2 and Option 1:

<em><u>hidden link</u></em>

In your View, add a Query Filter that filters based on the custom field value, set by a URL parameter, using the "in" comparison. See the attached screenshot. If you cannot see the Query Filter panel, scroll to the top right corner and click "Screen Options" to enable the Query Filter.

Let me know if you have questions about this, or if I misunderstood your request.

#1153162
Schermafdruk 2018-11-26 15.15.40.png
Schermafdruk 2018-11-26 15.15.15.png

Thank you for your reply. It helps me to specify my question.

So I created a Formidable form with a corresponding view that displays
1 the options the user has selected e.g. options 2 and 3
2 the value of the selected options; in my example: yellow and blue.
3 a Toolset view [wpv-view name="posts-tagged" "selectievakje=green"]

I filtered the Toolset view using the value from selectievakje as a tag name (see screenshot).
As said earlier I put the Formidable form field under Types control. I also patched Types (1798) and Views (1513) according to your errata list.

So far so good: the Toolset view displays the results as expected.

My question now is: how can I add a dynamic parameter to my view, like

[wpv-view name="posts-tagged" "selectievakje=[current option value(s) from selectievakje]"]?

So if a user checks options 2 and 3 the posts tagged yellow or blue are displayed in the Toolset view?

Can something like https://toolset.com/forums/topic/pass-dynamic-variable-as-parameter-to-view-on-a-page/ be helpful here?

Specifically, how can I pass multiple values (corresponding to multiple post tags) when a user checks multiple options?

#1153292

So if a user checks options 2 and 3 the posts tagged yellow or blue are displayed in the Toolset view?
If a user checks options 2 and 3, the URL parameter should look something like this:

<em><u>hidden link</u></em>

You need a shortcode that gets the parameters from the URL and inserts them in the View's shortcode attribute. I have a custom shortcode that will help. Add this to your child theme's functions.php file, or create a new snippet in Toolset > Settings > Custom Code:

add_shortcode( 'wpv-post-param', 'wpv_post_param_shortcode' );

function wpv_post_param_shortcode( $atts ) {
  if ( !empty( $atts['var'] ) ) {
    $var = (array)$_GET[$atts['var']];
    return esc_html( implode( ',', $var ) );
  }
}

You must register wpv-post-param in Toolset > Settings > Frontend Content > Third party shortcode arguments. This custom code will return a comma-separated list of values from the URL parameter you specify in the "var" attribute. The shortcode by itself will return:

yellow,blue

Here is how you would use this shortcode to pass in the values from the URL parameter "selectievakje":

[wpv-view name="posts-tagged" selectievakje="[wpv-post-param var='selectievakje']"]

Please note that this approach does not work with AJAX form submission. The page must be reloaded when the Form is submitted.

** Side note **
In general, you should never choose "save 0 to the database" because this option is known to cause problems in custom search Views and conditionals. Hopefully this option will be removed in an upcoming version, but for now it's advised to select "don't save anything to the database". After you make this change, you should save all the posts once again in wp-admin to set the correct values for these checkboxes. If you have questions about that, please create a separate ticket so we can discuss in detail.

#1153912
Schermafdruk 2018-11-27 14.52.37.png
Schermafdruk 2018-11-27 14.40.40.png

Thanks!
I added the shortcode function to my functions.php and registered the shortcode.
When accessing the url
domain.com/?page_id=205&selectievakje=some-tag
I get the list of posts tagged with "some-tag", as you would expect.

But I can't get the shortcode
[wpv-view name="berichten-volgens-tag" selectievakje="[wpv-post-param var='selectievakje']"]
to work; the only result i get is this (see screenshot).

#1154005

When you visit the page, you see the correct, filtered list of posts, bu you also say the View shortcode does not work. So I'm confused...how are you seeing the list of posts if the View shortcode isn't working? Is it possible for me to log in and see how you have this set up? If that's okay, please provide login credentials in the private reply fields here. Let me know where I can see this View on the front-end of your site.

#1154101

I'm not sure how this link is related to what we are discussing:
hidden link

Anyway, I changed the View filter setting to be "Tags slug in one of those set by the URL parameter selectievakje". Now check the results at these URLs:
hidden link
hidden link
hidden link

I think the results are showing as expected. These URLs show results that have the tags doe-modus, inspiratie-aanbod, or both doe-modus and inspiratie-aanbod, respectively.

#1154111
Schermafdruk 2018-11-27 23.08.40.png
Schermafdruk 2018-11-27 23.08.04.png

The urls you mentioned indeed work as they should. I created this page 205 to test the url parameters.

Now what is the relationship with
hidden link ?

This is the result I try to achieve: filling in a form, then retrieve the option values in order to use them as tags to filter posts.
This works perfectly using the url parameters, but not with the shortcode

[wpv-view name="berichten-volgens-tag" selectievakje="[wpv-post-param var='selectievakje']"]

in hidden link
This entry is created by
hidden link

The page to initially fill a form and create a corresponding view is hidden link

Unfortunately the shortcode just returns "] as you can see in the screenshot.

#1154734

This works perfectly using the url parameters, but not with the shortcode
The wpv-post-param shortcode requires URL parameters, it is not a replacement for URL parameters. I don't think I understand how everything fits together. How is the Toolset View added to this page?
hidden link
hidden link
I cannot find the View shortcode, probably because I do not know how Formidable Forms works. Can you help me?

#1154745

See the screenshots in my previous message:
hidden link (detail page)
is a view created by Formidable forms. It dynamically calls the content you fill in the form and displays it in an page like
hidden link

E.g. [71 show=value] displays the value of the options selected in the form.
In this example (see bottom of screenshot): Opties: persoonlijk verhaal, noodzaak
These option values are used in the wpv-view.

As a part of this view I added
[wpv-view name="berichten-volgens-tag" selectievakje="[wpv-post-param var='selectievakje']"]
This view should filter posts by tag and this tag is defined by the corresponding option value from the form submission.
(Field 71 in this case)

When I change this wpv-view to a particular tag, e.g. doe-modus, like
[wpv-view name="berichten-volgens-tag" selectievakje="doe-modus"]
It filters the list of posts with this tag, as it should.

When I use this as a url parameter like in
hidden link
it also works well.

So my guess is that the connection made with Types between the option values and the corresponding post tags works well, because it works as a url parameter. Is there something wrong with the shortcode? Am I using the shortcode in a wrong way?

As you can see at the bottom of entry/34 the shortcode just returns "].

#1154845
Screen Shot 2018-11-28 at 1.06.20 PM.png
Screen Shot 2018-11-28 at 1.06.29 PM.png

Well, the same Toolset View shortcode works outside of a Formidable Forms View. Look here, at Test 2:
hidden link

See the attached screenshots. Test 2 shows that the same shortcode works in the contents of a standard Page. There's something else going on. Perhaps Formidable Forms Views do not support multiple levels of nested shortcodes, or perhaps access to URL parameters inside a Formidable Forms View is not allowed for a reason that is beyond the control of Toolset.

Is it possible to move the Toolset View shortcodes out of the Formidable Forms View, and into the Page contents instead? As you can see in the tests above, the shortcode works fine in a Page. If not, this is most likely a compatibility issue that will take a considerable amount of time to solve. The Formidable Forms support team may have more information about nesting shortcodes, or it may require collaboration between our developers. Or, it may be possible to write your own custom shortcode that does what you want more effectively. Let me know how you would like to proceed.

#1155590

My issue is (more or less) resolved now. Thank you!