I have 2 forms connected by the ID of the first. When I create an entry in FORM B, i update one field in FORM A. But i'm trying to when deleting the entry in FORM B, that that one field in FORM A changes to another value. I tried "add_action('frm_before_destroy_entry', 'apaga_pd');" with the linked fields function, but this changes all my entries in FORM A. I just need to change that one specific entry. I'm doing this, but it is not working:
add_action('frm_before_destroy_entry', 'apaga_pd');
function apaga_pd($entry_id) {
$entry = FrmEntry::getOne($entry_id);
if ( $entry->form_id == 55 ) {//Change 113 to the ID of the first form
global $wpdb;
$first_field = $_POST['item_meta'][1352]; //change 25 to the ID of the field in your first form
$shared_entry = $_POST['item_meta'][1238];
$user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM ". $wpdb->prefix ."frm_items WHERE id=%d", $entry_id));
$entry_id = $wpdb->get_var("Select id from {$wpdb->prefix}frm_items where form_id='44' and user_id=". $user);
if ( $entry_id ) {
//update entry
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => 'Não'), array('item_id' => $shared_entry, 'field_id' => '1432'));//Change 48262 to the ID of the field you want to populate in Form B
}
}
} I would appreciate some help. Thanks in advance.
Thanks, but i can't acess my FTP for debugging.
I was also trying to use this but with the action "frm_before_destriy_entry", but it also doesn't work.
add_action('frm_after_create_entry', 'insere_Sim_mensal', 30, 2);
function insere_Sim_mensal($entry_id, $form_id){
if ( $form_id !== 55 ) { //Change 997 to the ID of your update form
return;
}
$entry_id = $_POST['item_meta'][1238]; //change 9353 to the ID of the field in your update form that has the entry id
$field_id = 1598; // change 9352 to the ID of the field in your main form that's to be updated
$new_value = 'No';// change 'Approved' to the value you want to set the field in your main form
$added = FrmEntryMeta::add_entry_meta( $entry_id, $field_id, null, $new_value );
if ( ! $added ) {
FrmEntryMeta::update_entry_meta( $entry_id, $field_id, null, $new_value );
}
}
You can use a File Manager plugin to access files on your server - https://wordpress.org/plugins/wp-file-manager/
My point is that if there's not an explicit, obvious problem with the code or you explain in detail what values are not being read/set in the way you want, you'll need to debug it yourself. The field ids are completely tied to your specific installation.
Please login or Register to submit your answer