Skip Navigation

[Resolved] Trying to create CRED form generic checkboxes populated by posts

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

Problem: I am trying to create generic checkboxes fields in my CRED form using a View to supply the options. The output of the View looks accurate but the checkboxes do not appear.

Solution:
The output of your View may look correct on the front-end of your site, but it may still contain some HTML and characters that need to be stripped out in order to be used to generate dynamic options. Add this code to your functions.php file:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
     
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '12345' ) { //Please adjust to your Views ID
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if ( 
            $start !== false
            && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
        ) {
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '<!-- wpv-loop-end -->' );
            $out = substr( $out, 0, $end );
        }
    }
    return $out;
}

Replace 12345 with the ID of your View.

Relevant Documentation: https://toolset.com/forums/topic/how-use-a-shortcode-instead-of-options-for-cred-forms/

This support ticket is created 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 Timothy 7 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#561634

I'm trying to create CRED form that has a checkboxes field that has a list of posts as the options, but nothing is appearing on the front-end.

This is what I have in the CRED content field:

[credform class="cred-form cred-keep-original"]
[cred_generic_field field='TestCheckboxes2' type='checkboxes' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":[],
"options":[
[wpv-view name="website-wizard-view-1"]
]
}
[/cred_generic_field]

[cred_field field="form_submit" value="Submit" urlparam=""]
[/credform]

And this is the View:

      <wpv-loop>[wpv-item index=1]{"value":"[wpv-post-id]","label":"[wpv-post-title]"}[wpv-item index=other],{"value":"[wpv-post-id]","label":"[wpv-post-title]"}
      </wpv-loop>

Which outputs:
{"value":"1757","label":"FAQs-With-Color-Background"},{"value":"1755","label":"FAQS-With-Side-Text"},{"value":"1756","label":"FAQs-Multiple-Sections"},{"value":"1749","label":"FAQs-With-Person-Image"}

Tim

#561741

The output looks okay, but it may have unwanted HTML characters that are breaking the option outputs. Have you added the raw text output filter to your functions.php file? This filter is described here:
https://toolset.com/forums/topic/how-use-a-shortcode-instead-of-options-for-cred-forms/

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
    
function prefix_clean_view_output( $out, $id ) {
    if ( $id == '6' ) { //Please adjust to your Views ID
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if ( 
            $start !== false
            && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
        ) {
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '<!-- wpv-loop-end -->' );
            $out = substr( $out, 0, $end );
        }
    }
    return $out;
}

Replace the '6' with your View's ID. Let me know if this does not resolve the problem and I'll take another look.

#561777

That works, thanks so much!