Skip Navigation

[Resolved] Output filters of a view to a CRED form

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

Problem: I would like to use the cred_save_data hook to capture the selected filters in a View.

Solution: Use the urlparam attribute on a CRED field to set the value of that field using a URL parameter. This only works on page load, and will not work with an AJAX update. You can write custom JavaScript and trigger it on certain events, like pagination and search results updates. The settings for these events can be found in the Advanced settings in your View editor.

Relevant Documentation: https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

This support ticket is created 7 years, 4 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 4 replies, has 2 voices.

Last updated by romanB-3 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#554432

Hello,
I have a view including a custom filter.
On frontend, after a user has filled this filter, his choices must be registered to a new custom post type.
I've been thinking on integrating the view into a cred form, then use cred save data to output the url parameters for instance... but I'm not quite sure about the possibility to do this with toolset.
What would be the best way to do this ?
Thank you.

#554488

If the View is set to update the URL and reload the page, then you can use the urlparam attribute on any CRED generic field to set its value. Then the user can submit the form to create a new post with these custom field values. More information about url parameters in a CRED field here:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field

In this example, the custom field slug is "myfieldslug" and the URL parameter looks like
this after the View reloads the page:

hidden link

[cred_field field="myfieldslug" urlparam="myurlparam"]

The value of the myfieldslug field in the new post will be 12345.

#554874

Works great in deed, thank you.
Would it be possible threw AJAX ?

#554889
custom-js.png

This will not work with AJAX, unfortunately, because the CRED field urlparam shortcode only works when the page loads. You need to modify the values when the filters change.

It is possible to trigger custom JavaScript code at certain events, like pagination and filter changes. See the attached screenshot showing these Advanced Settings in your View editor. If you cannot see these sections, you can use the Screen Options tab to enable them.

#555216

Thank you ; I'll explore this feature.
Thank you.