custom_calculate_scores
is called and processes the entry correctly.Current Setup:
Form ID: 9
Hidden Fields for Scores:
total_A (mzmip)
total_R (gaj2e)
total_I (b52q1)
total_D (4bfn0)
Error Logs:
Here are some relevant error log entries:
[Tue Jul 02 18:07:56.605812 2024] [php:notice] [pid 3524] [client 172.98.33.67:0] custom_calculate_scores called. Entry ID: 41, Form ID: 9, referer: https://theartdnaquiz.com/wp-admin/admin-ajax.php?action=frm_forms_preview&form=artdna-quiz-short
[Tue Jul 02 18:07:56.605895 2024] [php:notice] [pid 3524] [client 172.98.33.67:0] Form ID matches. Processing entry..., referer: https://theartdnaquiz.com/wp-admin/admin-ajax.php?action=frm_forms_preview&form=artdna-quiz-short
[Tue Jul 02 18:07:56.607358 2024] [php:notice] [pid 3524] [client 172.98.33.67:0] Panel: panel1, Field Key: 7w12w, Selection: AAA, referer: https://theartdnaquiz.com/wp-admin/admin-ajax.php?action=frm_forms_preview&form=artdna-quiz-short
...
[Tue Jul 02 18:07:56.610819 2024] [php:notice] [pid 3524] [client 172.98.33.67:0] Scores before saving: A: 8, R: 8, I: 6, D: 6, referer: https://theartdnaquiz.com/wp-admin/admin-ajax.php?action=frm_forms_preview&form=artdna-quiz-short
[Tue Jul 02 18:07:56.614759 2024] [php:notice] [pid 3524] [client 172.98.33.67:0] Update result - total_A: 233, value: 8, referer: https://theartdnaquiz.com/wp-admin/admin-ajax.php?action=frm_forms_preview&form=artdna-quiz-short
...
[Tue Jul 02 18:07:56.626506 2024] [php:notice] [pid 3524] [client 172.98.33.67:0] Retrieved Scores - total_A: , referer: https://theartdnaquiz.com/wp-admin/admin-ajax.php?action=frm_forms_preview&form=artdna-quiz-short
...
add_action('frm_after_create_entry', 'custom_calculate_scores', 20, 2);
function custom_calculate_scores($entry_id, $form_id) {
error_log("custom_calculate_scores called. Entry ID: $entry_id, Form ID: $form_id");
if ($form_id == 9) { // Replace 9 with your actual Form ID
error_log("Form ID matches. Processing entry...");
if (!class_exists('FrmEntryMeta')) {
error_log("FrmEntryMeta class not found.");
return;
}
// Define the attribute codes directly
$image_codes = array(
'AAA' => array('A' => 4, 'R' => 0, 'I' => 0, 'D' => 0),
// Additional codes omitted for brevity
);
// Define the fields for each panel
$fields = array(
'panel1' => '7w12w', // Field key for Panel 1
'panel2' => '771d8', // Field key for Panel 2
'panel3' => 'aeazn', // Field key for Panel 3
'panel4' => '4yt6k', // Field key for Panel 4
'panel5' => 'g3gxf', // Field key for Panel 5
// Add more panels as needed
);
$scores = array('A' => 0, 'R' => 0, 'I' => 0, 'D' => 0);
// Calculate scores based on selected images
foreach ($fields as $panel => $field_key) {
// Get the selected image code for the current panel
$selection = FrmEntryMeta::get_entry_meta_by_field($entry_id, $field_key, true);
error_log("Panel: $panel, Field Key: $field_key, Selection: $selection");
if ($selection && isset($image_codes[$selection])) {
// Get the attribute code for the selected image
$code = $image_codes[$selection];
// Update scores based on the attribute code
foreach ($code as $key => $value) {
$scores[$key] += $value;
}
}
}
error_log("Scores before saving: A: {$scores['A']}, R: {$scores['R']}, I: {$scores['I']}, D: {$scores['D']}");
// Save the scores back to hidden fields
FrmEntryMeta::add_entry_meta($entry_id, 'mzmip', null, $scores['A']); // total_A
FrmEntryMeta::add_entry_meta($entry_id, 'gaj2e', null, $scores['R']); // total_R
FrmEntryMeta::add_entry_meta($entry_id, 'b52q1', null, $scores['I']); // total_I
FrmEntryMeta::add_entry_meta($entry_id, '4bfn0', null, $scores['D']); // total_D
// Check the update results again
$total_A = FrmEntryMeta::get_entry_meta_by_field($entry_id, 'mzmip', true);
$total_R = FrmEntryMeta::get_entry_meta_by_field($entry_id, 'gaj2e', true);
$total_I = FrmEntryMeta::get_entry_meta_by_field($entry_id, 'b52q1', true);
$total_D = FrmEntryMeta::get_entry_meta_by_field($entry_id, '4bfn0', true);
error_log("Retrieved Scores - total_A: $total_A, total_R: $total_R, total_I: $total_I, total_D: $total_D");
}
}
I suggest checking the value returned by "FrmEntryMeta::add_entry_meta" and outputting it to error_log. There are many reasons it could fail: 1. It will fail if the meta_value already exists (in which case you need to use update_entry_meta and 2. if the field key is wrong. At first I thought it was because you were sending the key instead of the id, but it seems like both add_entry_meta and get_entry_meta_by_field will eventually convert it. Even though that's true you might try using FrmField::get_id_by_key('mzmip') where you currently have 'mzmip' and seeing if that helps.
thanks will be updating and checking this shortly!! really appreciate you taking the time!
Please login or Register to submit your answer