Create/Update Form B when Create/Update in Form A is done (regardless of user or number of entries)

Est. Reading: 3 minutes
By: bpilgrim
Created: 03/08/2018
Category:
Difficulty: Advanced

Create/Update Form B when Create/Update in Form A is done (regardless of user or number of entries)

×Warning: This tutorial was created 2462 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.
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

}
}

Leave a Reply

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
crosschevron-leftchevron-rightarrow-right