Automatically update a field in another form (with an additional lookup based on a Unique number)

By: Jason Ryan | Asked: 08/29/2023
ForumsCategory: General questionsAutomatically update a field in another form (with an additional lookup based on a Unique number)
Jason Ryan asked 11 months ago
I have an entry form for office staff to create a "works order" which is in my form 6 and each entry has a drop-downbox option within the field 121  (with options of Completed, Partially Completed, Not Completed) Each form entry also receives a unique Job No. in field 113 in the same form. -------------------------- I then have a secondary form for an engineer to fill out. Form 2 I added the code from the tutorial linked : https://formidableforms.com/knowledgebase/frm_after_create_entry/#kb-automatically-update-a-field-in-another-form However . . . after adding (and changing to my parameters
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 == 2){//Change 2 to the ID of the first form
global $wpdb;
$first_field = $_POST['item_meta'][531]; //change 531 to the ID of the field in your 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='6' and user_id=". $user);//Change 6 to the ID of the second form
foreach ($entry_ids as $e) {
$wpdb->update( $wpdb->prefix .'frm_item_metas', array('meta_value' => $first_field), array('item_id' => $e, 'field_id' => '121'));//Change 121 to the ID of the field to be updated automatically in your second form
}
}
}
 
I see that it updates every Entry in the original form under field ID 531 (with dropdown options of Completed, Partially Completed, Not Completed). Is there any additional code to be able to state only entries that match the unique job No. ??? So my original form with field 113 must match the number in the lookup in the second form . . . . field 110 ?? Any help would be greatly appreciated . . .   
Victor Font replied 11 months ago

Posting the sample code from the KnowledgeBase does nothing to help anyone troubleshoot your problem, which is probably why no one has answered your question yet. Please post your code that isn't working instead of sample code that does work.

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