Skip Navigation

[Resolved] My third party Form is not storing values in WP-Types checkboxes field.

This support ticket is created 4 years, 7 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by manishB-2 4 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#1573569

Hi Guys
I am using "Superforms" to submit Frontend Posts and I have created multiple checkboxes fields using WP-Types and connected the custom fields with my Superforms form but Checkboxes fields are not storing data. Because superforms is storing Comma-separated values for checkboxes, but Toolset stores serialized array for checkboxes values. So is there any option to make it work somehow either by making any change on Superforms or in toolset?

I am using superforms because of lack of multiple designing issues with toolset. I can't make my toolset based post form more interactive like real time errors reporting, Numbers slider fields etc.

So let me know if there is any solution, you can provide.

#1574189

Hello and thank you for contacting the Toolset support.

To be able to save the checkboxes as a serialized array, you will need to hook into superforms logic and convert the comma-separated value into an array.
I searched for hook documentation on the plugin site but I could not find any.
You may need to ask the plugin's author to add a filter that will let you convert the values types.

I hope this helps. Let me know if you have any questions.

#1574719

Thanks for your response,
So i asked for help from Plugin developer and provided a code sample which was used for Gravity form's checkboxes values to convert as serialized array, So he wrote down a code but that's not working and I may need your help to make it work. I am really in trouble if it doesn't work. So Please assist me somehow. Below is the code given by the plugin developer.

function f4d_convert_metadata( $attr ) {
    // CHANGE THIS LIST TO ANY META DATA YOU NEED TO CONVERT
    $meta_keys = array( 'form_meta_key1', 'form_meta_key2', 'form_meta_key3' );
    // DO NOT CHANGE BELOW CODE
    $post_id = $attr['post_id'];
    foreach($meta_keys as $meta_key){
        // Grab meta value
        $meta_value = get_post_meta( $post_id, $meta_key, true );
        // Convert to Array
        $meta_value = explode(',', $meta_value);
        // Save it as array
        update_post_meta( $post_id, $meta_key, $meta_value );
    }
}
add_action('super_front_end_posting_after_insert_post_action', 'f4d_convert_metadata', 10, 1);

Below is the code which I found in your forum used for gravity form. So if possible, please

// capture a GF checkbox field values and serialize so WP Types CPT can display checked properly
add_action("gform_after_submission", "add_custom_post_meta", 10, 2);
function add_custom_post_meta($entry, $form) {
    $arr = array(
        array('my-checkboxes1', '123'),
        array('my-checkboxes2', '456'),
        array('my-checkboxes3', '789'),
    );
    foreach($arr as $v){
        $items = get_checkbox_value( $entry, $v[1] );
        $value = my_checkboxes_func($items, $v[0]);
        update_post_meta($entry['post_id'], 'wpcf-' . $v[0], $value);
    }
}
 
function get_checkbox_value( $entry, $field_id ){
   
    //getting a comma separated list of selected values
    $lead_field_keys = array_keys( $entry );
    $items           = array();
    foreach ( $lead_field_keys as $input_id ) {
        if ( is_numeric( $input_id ) && absint( $input_id ) == $field_id ) {
            $items[] = GFCommon::selection_display( rgar( $entry, $input_id ), null, $entry['currency'], false );
        }
    }
    //$value = GFCommon::implode_non_blank( ', ', $items );
   
    return $items;
}
 
 
function my_checkboxes_func($items = array(), $types_field = '') {
    $fields = WPCF_Fields::getFields();
    $arr = array();
    if(isset($fields[$types_field]['data']['options'])){
        foreach ($fields[$types_field]['data']['options'] as $k=> $v){
            if(in_array($v['set_value'], $items)){
                $arr[$k] = array($v['set_value']);
            }
        }
    }
    return $arr;
}
#1577041

As far as I can understand from the first code, this action is executed after the superforms form saves the post on the database.
You will need to update line 3 with the custom fields slugs prefixed with "wpcf-" as it is done on the second code at line 12. Let's say your checkboxes slug is called "post-features", you will need to update line 3 from:

    $meta_keys = array( 'form_meta_key1', 'form_meta_key2', 'form_meta_key3' );

To:

    $meta_keys = array( 'wpcf-post-features' );

If this does not help, please provide me with a Duplicator copy of your website and let me try locally. Your next reply will be private to share the download link safely.
https://toolset.com/faq/provide-supporters-copy-site/