Skip Navigation

[Resolved] Is it possible to apply filter before a value is displayed on a form?

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 3 voices.

Last updated by Beda 6 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#592039

Before CRED form values are saved in the DB they're converted (I use `cred_save_data` hook). When I display values on the page I have to convert them back to a user-readable format so I use Types `wpcf_fields_slug_${field_slug}_value_display` filters.

So far it works fine.

The problem is that I also want to filter field's values that are displayed on the CRED edit form. I can't find any hook in the CRED documentation that will allow me to do it.

I know that I can modify the values on the front-end (with JS), but this is neither good nor elegant solution.

#592288

Hi, unfortunately there's no documented filter available for this type of manipulation in CRED. However, you can use the "value" attribute of any cred field shortcode to specify a different value. For instance, you could create a custom shortcode that retrieves the value of that particular custom field for that particular post, and performs whatever filtering is necessary, then returns the filtered value.

[cred_field field="field-slug" post="post-type-slug" value="[custom_filtered_value field='field-slug' post='12345']"]
function custom_filtered_value_func ($atts) {
    $post_id = $atts['post'];
    $field = $atts['field'];
    $value = get_post_meta($post_id, 'wpcf-' . $field, true);
    // your conversion here
    return $value;
}
add_shortcode('custom_filtered_value ', 'custom_filtered_value_func ');
#592550

Thanks Christian. This isn't a perfect solution, but it's still a better solution than JS-based replacements done on the front-end.

PS
Can you mark this topic as a feature request? It would be good if CRED had such filters.
I'm not even sure shouldn't it be marked as a bug report. I expected that Types `wpcf_fields_slug_${field_slug}_value_display` filters would work for CRED forms. But these filters are not applied when types fields are displayed on the form. They work only when Types fields are displayed using types shortcodes. I'm not sure is it a bug because I'm not sure what is the expected behaviour.

#594812

Sure, I will reassign this ticket to Beda. He handles feature requests for CRED, and will follow up with you here.

#595048

I am sorry, you seem to not own a license for Toolset CRED.
If you do, can you register it, so I can see this on the profile of yours?

In order to change values in a CRED form, existing values I mean, you can use Christian's Solution, we do currently not have API in place for that.

I will discuss the feature and see if we can add something.

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.