Tell us what you are trying to do?
Hello,
We have a custom code in place that was provided by your awesome support specialist Christian Cox. The code calculates all the custom fields that are selected on the post page.
We will have several forms that will need to have this feature. Currently, the Structural Systems form works perfectly.
We have duplicated the code and applied it to the new form "Electrical Systems" but when we "Activate" the code it breaks the website.
You will have to log in to view the pages and code, please let me know when it is safe to share login credentials.
Name of WORKING code:
cred_save_data.php
BROKEN CODE Name:
electrical_cred_save_data
FORM that is used to calculate custom fields:
hidden link
Test Post that will display calculations:
• Total Inspected
• Total Not Inspected
• Total Ok
• Total Deficient
hidden link
Is there a similar example that we can see? Please let me know when it is safe to share access credentials
What is the link to your site? hidden link
Hi,
Thank you for contacting us and I'd be happy to assist.
When you duplicated the working code snippet, did you change the name of the function in the new code snippet? The same name function can't be used again and would result in an error.
For example, suppose, your first code snippet, had the function named "my_save_data_function":
add_action('cred_save_data', 'my_save_data_function',10,2);
function my_save_data_function($post_id, $form_data)
{
....
}
Now, when you'll duplicate it for some different form, you'll need to change the function name "my_save_data_function" to something else, to avoid the error:
add_action('cred_save_data', 'my_save_data_function_electrical',10,2);
function my_save_data_function_electrical($post_id, $form_data)
{
....
}
I hope this helps and in case the issue still persists, you're welcome to share temporary admin login details, in reply to this message.
Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.
regards,
Waqar
Hello Waqar,
I wanted to make sure you received my previous reply.
Please let me know if you need any more information.
Thank you sir!
Thank you for sharing these details.
During troubleshooting, I noticed that the field "Total Inspected Electrical" has slug "total-inspected-electric", but in the code snippet at line# 37, "total-inspected_electric" is used.
( note the use of _ instead of - before electric )
Please change that line from:
update_post_meta( $post_id, 'wpcf-total-inspected_electric', $total_inspected_electric );
To:
update_post_meta( $post_id, 'wpcf-total-inspected-electric', $total_inspected_electric );
We appreciate all your help Waqar! My issue is resolved now. Thank you!