Using frmapi_post_response will not update field in form

By: Nehla baananou | Asked: 11/11/2024
ForumsCategory: Code HelpUsing frmapi_post_response will not update field in form
Nehla baananou asked 3 weeks ago
Hello, I need your help I have integrated this code into my site so that I can update an entry in Form A in a field in Form B \\\\\\\" add_action(\\\\\\\'frm_after_create_entry\\\\\\\', \\\\\\\'link_fields\\\\\\\', 30, 2);
add_action(\\\\\\\'frm_after_update_entry\\\\\\\', \\\\\\\'link_fields\\\\\\\', 10, 2);
function link_fields($entry_id, $form_id){
if($form_id == 12){ // Change 10 to the ID of Form A
global $wpdb;
$first_field = $_POST[\\\\\\\'item_meta\\\\\\\'][116]; // Change 71 to the ID of the field in Form A
$user = $wpdb->get_var($wpdb->prepare(\\\\\\\"SELECT user_id FROM \\\\\\\". $wpdb->prefix .\\\\\\\"frm_items WHERE id=%d\\\\\\\", $entry_id)); // Récupérer l\\\\\\\'ID d\\\\\\\'une entrée spécifique de Form B à mettre à jour
$entry_ids = $wpdb->get_col($wpdb->prepare(\\\\\\\"SELECT id FROM \\\\\\\". $wpdb->prefix .\\\\\\\"frm_items WHERE form_id=%d AND user_id=%d\\\\\\\", 11, $user)); // Change 9 to the ID of Form B // Exemple de mise à jour d\\\\\\\'une entrée spécifique, par exemple, la dernière entrée créée
if (!empty($entry_ids)) {
$specific_entry_id = end($entry_ids); // Récupérer l\\\\\\\'ID de la dernière entrée créée
$updated = $wpdb->update($wpdb->prefix .\\\\\\\'frm_item_metas\\\\\\\',
array(\\\\\\\'meta_value\\\\\\\' => $first_field),
array(\\\\\\\'item_id\\\\\\\' => $specific_entry_id, \\\\\\\'field_id\\\\\\\' => 105) // Change 67 to the ID of the field to be updated
); if ($updated) {
error_log(\\\\\\\'Successfully updated entry ID: \\\\\\\' . $specific_entry_id);
} else {
error_log(\\\\\\\'Failed to update entry ID: \\\\\\\' . $specific_entry_id);
}
}
}
} \\\\\\\"   it\\\\\\\'s ok it is functional but my cproblem is that when a User (Client) fills Form A another user (example: Admin) fills Form B in this case the code will not be functional that is to say the field in Form A will not be updated.  
I need your help to improve the code so that a User A fills a FORM A the field concerned in FORM B filled by a USER B will be updated.
1 Answers
Victor Font answered 3 weeks ago
First, the code is unreadable and in the title you ask about frm_api_response, yet there's nothing in your post about that hook. Please use pastebin or gist to post your code and please rephrase your question so we can understand what you are actually asking since it has nothing to do with frmapi_post_response.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right