Saltar navegación

[Resuelto] Add the checkbox values on form submission and save as total

This support ticket is created hace 2 años, 10 meses. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

Este tema contiene 5 respuestas, tiene 2 mensajes.

Última actualización por Chris hace 2 años, 10 meses.

Asistido por: Minesh.

Autor
Mensajes
#2434073

Tell us what you are trying to do?
I have a form that is basically a checklist made up of checkboxes that save a value of 1 when ticked and 0 when not. When the user edits the form, I want to add up all the checkbox values and save that as another field to feed into the progress indicator. I know to use the cred_save_data hook but I have no idea how to add up the field values (and ideally turn that into a number out of 100) there will be 8 in total.

thanks
Chris

#2434079

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share problem URL where you added the edit form as well as admin access details and let me review your setup first and will get back to you with the possible solution.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2434877

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

I've added the Toolset form's hook "cred_save_data" to the "Custom Code" section offered by Toolset:
=> enlace oculto

add_action('cred_save_data', 'func_calculate_completion_value',10,2);
function func_calculate_completion_value($post_id, $form_data) {
    // if a specific form
    if ($form_data['id']==213) {
      
      $education= get_post_meta($post_id,'wpcf-education',true);
      $professional= get_post_meta($post_id,'wpcf-professional',true);
      $accreditation= get_post_meta($post_id,'wpcf-accreditation',true);
      $australia_training= get_post_meta($post_id,'wpcf-australia-training',true);
      $consultation= get_post_meta($post_id,'wpcf-consultation',true);
      $treatment = get_post_meta($post_id,'wpcf-treatment',true);
      $assessment = get_post_meta($post_id,'wpcf-assessment',true);
      
      $completion = (($education + $professional + $accreditation + $australia_training +
        			$consultation + $treatment + $assessment)/8)*100 ;
      
      update_post_meta($post_id,'wpcf-completion',$completion);   
      
        
    }
}

I can see when I checkmark 4 checkboxes it does display the progress bar to 50:
=> enlace oculto

You are welcome to adjust the above code as required.

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

#2435421

Thanks Minesh, that's awesome.
Can I just ask where do I find documentation or samples of what you've done there... the get_post_meta etc?
I can look at what you've done there and figure out how it works now.
But I was looking for info initially to try and figure this out myself but couldn't find that sort of thing anywhere.

thanks again.
Chris

#2435625

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

#2436251

Thank you so much for the solution and where to find future info for myself