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

Slack Signup
Newsletter Optin
Help Desk

Update a field of an entry from another form after submission when building a forum

Labels

This Discussion is public

Notifications

Pls add below code to you function.php

when building a forum with formidable pro and when you need to update a field of main form from a child form you can use below.

pls note that 115 ([get param=entry]) gets the entry ID of the main form.


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 == 15){// Change 15 to the ID of the first form

global $wpdb, $frmdb;

$first_field = $_POST['item_meta'][117]; // change 117 to the ID of the field in your first form
$e = $_POST['item_meta'][115]; // change 115 to the ID of the second form which is the entry id for child form
$entry_ids = $wpdb->get_col("Select id from $frmdb->entries where form_id='14'");//Change 14 to the ID of the second form

$wpdb->update($frmdb->entry_metas, array('meta_value' => $first_field), array('item_id' => $e, 'field_id' => '109'));//Change 109 to the ID of the field to be updated automatically in your second form

}

}

Just a heads up.. This can be done with the API as well. The settings for your example would look like this:

URL:
[siteurl]/wp-json/frm/v2/entries/[115]

And the key/value pairs:
key: 109 value: [117]

No code needed.

Being a total none-php person, I spent hours trying to get @Sailor's code to work without success.  This is what finally worked for me. I am not sure it's proper coding, but it worked for me. I hope it saves another person hours of labour.

When you want the change to affect ALL entries in the Child form use the full code below
When you want the change to affect ONLY the entry with the ID [115], comment out or delete the "foreach ($entry_ids as $e)" line

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 == 15){//Change 15 to the ID of the first form
global $wpdb;
$first_field = $_POST['item_meta'][117]; //change 117 to the ID of the field in your first form
$e = $_POST['item_meta'][115]; // change 115 to the ID of the second form which is the entry id for child form
$entry_ids = $wpdb->get_col("Select id from ". $wpdb->prefix ."frm_items where form_id='14'");//Change 14 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' => '109'));//Change 109 to the ID of the field to be updated automatically in your second form
}
}

Discussion closed.