Skip Navigation

[Resolved] How-to: Populating options in a generic checkboxes field with views shortcode

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

Problem: I would like to use a View to populate dynamic options in a generic CRED field.

Solution: Review the information in this ticket for more information:
https://toolset.com/forums/topic/hot-to-populating-options-in-a-generic-checkboxes-field-with-views-shortcode/

Relevant Documentation: https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/

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

Last updated by markL 7 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#538177
views-shortcode-output.PNG
form rendering with options manually input.PNG

Hi There,

I'm trying to populate the options of a generic checkboxes field on a CRED form with views shortcode output as I understand is the intention of the plugin.

The views shortcode outputs the required text, however the field does not display in the form.
When the output from the view is copied into the options attribute, the field displays.

On inspection, there is a heap of HTML generated by the views shortcode that may be interfering with the form rendering as discussed here:

https://toolset.com/forums/topic/dynamic-cred-generic-field-options/

Form code

[cred_generic_field field='SelectChildren' type='checkboxes' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[ [wpv-view name="select-children-shortcode"] ]
}
[/cred_generic_field]              
[wpv-view name="select-children-shortcode"]

Views code

[wpv-layout-start]
  [wpv-items-found]
    <!-- wpv-loop-start -->
      <wpv-loop>
          {"value":"[wpv-post-id]","label":"[wpv-post-title]"},
      </wpv-loop>{"value":"all","label":"all"}
    <!-- wpv-loop-end -->
  [/wpv-items-found]
    [wpv-no-items-found]
	   <strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
    [/wpv-no-items-found]
[wpv-layout-end]

You can see the output of the form code below, also page html showing excess html.

#538321

Hi! Sorry for the delay getting back to you, we have been unusually busy. Please review the filter described here:
https://toolset.com/forums/topic/how-use-a-shortcode-instead-of-options-for-cred-forms/#post-419301

Add this filter to your functions.php file to strip out all extra characters so that your options list is usable by the generic field. Please let me know if you run into any issues with this and I'll be glad to help. Thanks!

#538326

Thanks for the tip. Works fine.

Mark