The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Automatically update a field in another form
I (admin) would like to use this code to update a field in form A and have it update similar field in form B, which is the users form, so the code as is wont work. To link forms I added the entryid from form B and inserted into a field I called, entryid. Contact email address is also the same in both forms.
Thanks,
Geno
March 6, 2019 at 10:28 am
The frm_after_update_entry example code for automatically updating a field in another form is based on forms that have been entered by logged in users, not an admin. The user id has to be identical in both Form A and Form B to work. You'll have to customize that code to work based on entryid instead of user id.
March 6, 2019 at 11:05 am
Thanks. I do understand I have to modify code, but not sure how. I'll go ahead and give it a shot.
March 7, 2019 at 1:36 pm
I tried the following code and it didn't work. I'm trying to update the second form where the entry_id of second form equals the entryid field, 437 of first form. I made in bold the code that I thought would work, but I got a 500 error.
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 == 39){//Change 39 to the ID of the first form
global $wpdb;
$paypal_field = $_POST['item_meta'][436]; first form
$entryid_field = $_POST['item_meta'][437]; first form
$user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM ". $wpdb->prefix ."frm_items WHERE id=%d", $entry_id));
$entry_ids = $wpdb->get_col("Select id from ". $wpdb->prefix ."frm_items where form_id='32' and entry_id=$entryid);//Change 32 to the ID of the second form
foreach ($entry_ids as $e)
$wpdb->update( $wpdb->prefix .'frm_item_metas', array('meta_value' => $paypal_field), array('item_id' => $e, 'field_id' => '410'));//Change 410 to the ID of the field to be updated automatically in your second form
}
}
March 7, 2019 at 9:40 pm
505 because lines 6 & 7 are not commented appropriately at the end?
first form should be //first form
March 8, 2019 at 7:29 am
Thanks Bobby for noticing the comments weren't correct. I also noticed I made an error on the variable created $entryid_field then called $entryid. I'll go ahead and make changes and hopefully it'll work
March 8, 2019 at 1:43 pm
I made all the necessary changes, but it's still not working. What am I missing?
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 == 39){//first form
global $wpdb;
$paypal_field = $_POST['item_meta'][436]; //first form
$entryid_field = $_POST['item_meta'][437]; //first form
$entry_ids = $wpdb->get_col("Select id from ". $wpdb->prefix ."frm_items where form_id='32' and entry_id=$entryid_field);//second form
foreach ($entry_ids as $e)
$wpdb->update( $wpdb->prefix .'frm_item_metas', array('meta_value' => $paypal_field), array('item_id' => $e, 'field_id' => '410'));//second form
}
}
March 8, 2019 at 3:23 pm
You are missing of matching braces and parens. Here's the corrected code:
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 == 39){ //first form
global $wpdb;
$paypal_field = $_POST['item_meta'][436]; //first form
$entryid_field = $_POST['item_meta'][437]; //first form
$entry_ids = $wpdb->get_col("Select id from ". $wpdb->prefix ."frm_items where form_id='32' and entry_id = $entryid_field"); //second form
foreach ($entry_ids as $e) {
$wpdb->update( $wpdb->prefix .'frm_item_metas', array('meta_value' => $paypal_field), array('item_id' => $e), 'field_id' => '410');//second form
}
}
}
Discussion closed.