Skip Navigation

[Closed] Checkbox Comma Separated Values to Array conversion issue

This support ticket is created 4 years, 6 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)

This topic contains 12 replies, has 2 voices.

Last updated by Jamal 4 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#1652851

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);

So my old support ticket is already there but That ticket is closed. and I had replied back to that ticket and shared my site access in private message. So please visit https://toolset.com/forums/topic/my-third-party-form-is-not-storing-values-in-wp-types-checkboxes-field/#post-1652847 to get my login credentials. and you can also find complete details of my request in this old ticket.

Waiting to hear from you.

#1652901

Hello,

My apologies for not replying to your last message, I must have skipped the email notification because the ticket is already marked as resolved.

I'll try to understand how the Superform is working and I'll get back to you if I got a solution or if I needed more info.

Best regards,
Jamal

#1653109

Jamal, Can you please help me make it work soon, Because on Monday I have to put it live and working.

#1654443

Hi Jamal or Anyone from Toolset support,
I request you guys to please look into this issue and help me fix it please.

#1655541

My apologies for the late reply, I do not work on Sundays and Mondays. I tried to investigate the code on your website using PHP debugging but the debug log does not seem to get created.
I tried to configure the debugging on wp-config.php, in php.ini and .user.ini to no avail. I can't move forward on your website. Would you allow me to take a Duplicator copy of your website? And to not waste time, I prefer that you prepare the copy manually in case of failure. Please use filter to reduce the size of the copy as described in this video around 1:00 hidden link
If Duplicator fails to create a copy, we'll need a database copy/export, plugins, and theme folders, all in a zip file.
Your next reply will be private to let you share the download link safely.

#1655713

Hi Jamal,
That is staging site. So you can do anything that you want. It's just for testing pupose. So do what you need to do.

#1655847

Thank you!

I am finding trouble taking a complete Duplicator copy. For the moment, I took a database copy and the required plugins. This may take a couple of hours. Hopefully, I'll get back to you in 1 or 2 hours.

#1656199

While debugging why this is not working on my local setup, I am encountering a PHP notice from the superforms frontend posting, this is probably stopping the custom code from execution.

[09-Jun-2020 19:30:35 UTC] PHP Notice:  unserialize(): Error at offset 0 of 6 bytes in C:\sites\clone-1652851\wp-content\plugins\super-forms-front-end-posting\super-forms-front-end-posting.php on line 906
[09-Jun-2020 19:30:35 UTC] PHP Stack trace:
[09-Jun-2020 19:30:35 UTC] PHP   1. {main}() C:\sites\clone-1652851\wp-admin\admin-ajax.php:0
[09-Jun-2020 19:30:35 UTC] PHP   2. do_action() C:\sites\clone-1652851\wp-admin\admin-ajax.php:175
[09-Jun-2020 19:30:35 UTC] PHP   3. WP_Hook->do_action() C:\sites\clone-1652851\wp-includes\plugin.php:478
[09-Jun-2020 19:30:35 UTC] PHP   4. WP_Hook->apply_filters() C:\sites\clone-1652851\wp-includes\class-wp-hook.php:311
[09-Jun-2020 19:30:35 UTC] PHP   5. SUPER_Ajax::send_email() C:\sites\clone-1652851\wp-includes\class-wp-hook.php:287
[09-Jun-2020 19:30:35 UTC] PHP   6. do_action() C:\sites\clone-1652851\wp-content\plugins\super-forms\includes\class-ajax.php:2978
[09-Jun-2020 19:30:35 UTC] PHP   7. WP_Hook->do_action() C:\sites\clone-1652851\wp-includes\plugin.php:478
[09-Jun-2020 19:30:35 UTC] PHP   8. WP_Hook->apply_filters() C:\sites\clone-1652851\wp-includes\class-wp-hook.php:311
[09-Jun-2020 19:30:35 UTC] PHP   9. SUPER_Frontend_Posting->before_email_success_msg() C:\sites\clone-1652851\wp-includes\class-wp-hook.php:287
[09-Jun-2020 19:30:35 UTC] PHP  10. unserialize() C:\sites\clone-1652851\wp-content\plugins\super-forms-front-end-posting\super-forms-front-end-posting.php:906

This is the code that I was testing:

error_log('convert-superform-checkboxes'); // <-- this gets called the rest does not.
// Put the code of your snippet below this comment.

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

Maybe this is due to the version of PHP in my local setup, I am on 7.3. Can you please reach to the super forms team and ask them about this? If you would like I can provide a test server on our platform, or you can ask your hosting provider to setup PHP debugging in your staging website and we can continue on it.

My apologies if this is taking too much time, but I got stuck again on another plugin issue.

#1656503

Is there any possibility, you can write down a working custom function? or make some customization on it? Because I have submitted a support request to Super Forms developer but Didn't get any response. So if possible, please reply back.

#1656973

I'll help you with the required snippet, but I do not see how that will be helpful if the function hooked is never executed. Also, I won't be sure if the code is working as expected if I do not test it. If the hooked function is never executed, our code will not be executed.

Anyway, check this snippet hidden link

It uses types_get_field function to get the definition of the field in Toolset. The definition contains all the possible values in the case of a checkboxes field(not to confuse with checkbox field) and it also explains how to build the value array and save it with update_post_meta

#1657745

Hi Jamal,
So I got response from Super Forms developer and he told that the long we showed here is not an error. Its just PHP Notice which notifies you. This is what he replied

No, the log isn't an error it's just a Notice, nothing wrong about this.
Super Forms is calling the function "unserialize()" which passes a string, and checks if it is possible to unserialize the string, if not it returns FALSE, and throws an E_NOTICE (which is PHP Notice: in your logs.
Docs:
hidden link

The custom code has nothing to do with that error.
The Snippet URL you shared is a bit complicated for me because I am not very much expert in Custom PHP work. So use the same hook, can make required updates on the custom function.

I am waiting to hear from you.

Thank you
Manish

#1658479

Hi Jamal
I am still waiting to hear from you.

Please help me write down a working function. And the current hook is actually working. It just needs a proper function that can convert the comma-separated values into Array values, It is really important feature to work for my project. So Please help me do this anyhow.

#1660005

Sorry for the late reply, I was on a sick leave yesterday.

In fact, it is just a notice, it is not an error, but that notice is probably blocking the execution of the code. In the custom code, the first line, which is outside of the hook is called and it writes a line on the debug.log file, but the lines 9, 13, and 18 are never called, this means to me, that the whole function is not called.
I do not assume that the notice is the issue. No. But simply, the function code is never called. Which means, that whatever custom code I'll share with you, it is not called, so how can I or you, test it and be sure it is working.

I suggest that you ask your hosting provided to activate debugging, this will let the lines (1, 9, 13, and 18) write into the debug.log file. This way, we(toolset support, you, and Super forms support) can work together on this issue on your server. I can also create an installation on our platform and provide you and the Super forms support with access, and we can work on it there.

The topic ‘[Closed] Checkbox Comma Separated Values to Array conversion issue’ is closed to new replies.