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
Create/Update Form B when Create/Update in Form A is done (regardless of user or number of entries)
add_action('frm_after_create_entry', 'create_entry', 30, 2);
$arr = array();
function create_entry($entry_id, $form_id)
{
if ( $form_id == 66 ) //ID of form A
{
global $wpdb;
$myiddata = $entry_id + 2;
$form2 = '111'; //ID of Form B
$user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->prefix}frm_items WHERE id=%d", $entry_id));
if ( !$user ) {
return;
}
$entry_id = $wpdb->get_var("Select id from {$wpdb->prefix}frm_items where form_id='" . $form2 . "' and user_id=". $user);
$report_title = $_POST['item_meta'][7590]; //Field ID in form A
$customer_name = $_POST['item_meta'][6513]; //Field ID in form A
$parent_form_status = $_POST['item_meta'][6582]; //Field ID in form A
$parent_form_key = $_POST['item_meta'][8202]; //Field ID in form A
$edit_entry_link = $_POST['item_meta'][8207]; //Field ID in form A
$date = $_POST['item_meta'][8167]; //Field ID in form A
$layout = $_POST['item_meta'][8213]; //Field ID in form A
$parent_form_id = $_POST['item_meta'][8203]; //Field ID in form A - Page ID field
FrmEntry::create(array(
'form_id' => $form2,
'item_key' => $report_title , //change entry to a dynamic value if you would like
'frm_user_id' => $user,
'item_meta' => array(
8194 => $report_title, //Field ID in form B
8195 => $customer_name, //Field ID in form B
8204 => $parent_form_status, //Field ID in form B
8201 => $user, //Field ID in form B - User ID field
8200 => $parent_form_id, //Field ID in form B - Page ID field
8198 => $parent_form_key, //Field ID in form B
8206 => $edit_entry_link, //Field ID in form B
8205 => $layout, //Field ID in form B
8196 => $date, //Field ID in form B
8199 => $myiddata //Field ID in form B for Parent Entry ID
),
));
}
}
add_action('frm_after_update_entry', 'update_entry', 10, 2);
function update_entry($entry_id, $form_id)
{
if ( $form_id == 66 ) //ID of form A
{
global $wpdb;
$id= $_POST['id'];
$myid = $id - 1;
$form2 = '111'; //ID of Form B
$user = $wpdb->get_var($wpdb->prepare("SELECT * FROM {$wpdb->prefix}frm_items WHERE id=%d", $entry_id));
if ( !$user ) {
return;
}
$mydata = $wpdb->get_results ("Select * from {$wpdb->prefix}frm_item_metas where item_id=".$myid);
$report_title = $_POST['item_meta'][7590]; //Field ID in form A
$customer_name = $_POST['item_meta'][6513]; //Field ID in form A
$parent_form_status = $_POST['item_meta'][6582]; //Field ID in form A
$parent_form_key = $_POST['item_meta'][8202]; //Field ID in form A
$edit_entry_link = $_POST['item_meta'][8207]; //Field ID in form A
$layout = $_POST['item_meta'][8205]; //Field ID in form A
$date = $_POST['item_meta'][8167]; //Field ID in form A
$parent_form_id = $_POST['item_meta'][8203]; //Field ID in form A - Page ID field
$assigned_user = $_POST['item_meta'][6583]; //Field ID in form A - User ID field
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $customer_name),array('item_id' => $myid, 'field_id' => 8195)); //Field ID in form B
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $parent_form_status),array('item_id' => $myid, 'field_id' => 8204)); //Field ID in form B
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $report_title),array('item_id' => $myid, 'field_id' => 8194)); //Field ID in form B
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $parent_form_id),array('item_id' => $myid, 'field_id' => 8200)); //Field ID in form B - Page ID field
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $parent_form_key),array('item_id' => $myid, 'field_id' => 8198)); //Field ID in form B
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $edit_entry_link),array('item_id' => $myid, 'field_id' => 8206)); //Field ID in form B
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $layout),array('item_id' => $myid, 'field_id' => 8205)); //Field ID in form B
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $date),array('item_id' => $myid, 'field_id' => 8196)); //Field ID in form B
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $assigned_user),array('item_id' => $myid, 'field_id' => 8201)); //Field ID in form B - User ID field
}
}
April 26, 2018 at 11:56 am
Hi,
I need to be able to have one form update the entries in another form upon submission.
I'm not very code savvy and would like to ask, how would I implement your solution?
Any advice would be greatly appreciated, thank you!
April 26, 2018 at 2:47 pm
Hi Prosold, You would use the code in this post like any other Formidable Hook - You can place it in functions.php, or use the snippets plugin. I use the snippets plugin. Just note that in your implementation instead if $myiddata = $entry_id + 2; you will probably need to omit the +2 part and just use: $myiddata = $entry_id;
Hope this helps you along. :)
B.
Discussion closed.