This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This hook allows you to do something with the data entered in a form after it is submitted. This is the best place for a custom action after form submit.
Usage
add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
Parameters
- $entry_id (integer)
- $form_id (integer)
Examples
Send submitted entry to another site
Sometimes there is a need to send your data on the another site without actually redirecting to it. This will require quite a bit of customization to put together the url needed.
add_action('frm_after_create_entry', 'yourfunctionname', 30, 2);
function yourfunctionname($entry_id, $form_id){
if($form_id == 5){ //replace 5 with the id of the form
$args = array();
if(isset($_POST['item_meta'][30])) //replace 30 and 31 with the appropriate field IDs from your form
$args['data1'] = $_POST['item_meta'][30]; //change 'data1' to the named parameter to send
if(isset($_POST['item_meta'][31]))
$args['data2'] = $_POST['item_meta'][31]; //change 'data2' to whatever you need
$result = wp_remote_post('http://example.com', array('body' => $args));
}
}
Create a new WordPress Category
If you want a separate form for adding categories, you can use this code to create them. If you want to keep the category creation inside the same form that creates posts, this custom code is not needed. Use a "Tags" field instead, and map it to your category in the "create posts" settings tab.
add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){
if($form_id == 5){ //change 5 to the ID of your form
if(isset($_POST['item_meta'][25])){ //change 25 to the ID of the field used to add a category
$category_name = 'category'; //if you're using a custom taxonomy, change this to the correct name
if(function_exists('term_exists'))
$term_id = term_exists($_POST['item_meta'][25], $category_name);
else
$term_id = is_term($_POST['item_meta'][25], $category_name);
if(!$term_id) $term_id = wp_insert_term($_POST['item_meta'][25], $category_name);
}
}
}
Delete the entry, leave the post
When the "Do not store entries submitted from this form" box is checked, but you are also creating posts, neither the entry or the post are saved. If you'd like the entry deleted, but the post to remain, do not check that box, but use this instead.
add_action( 'frm_after_create_entry', 'after_entry_created', 60, 2 );
function after_entry_created( $entry_id, $form_id ) {
global $wpdb;
// unlink the post from the entry
$unlinked = $wpdb->update( $wpdb->prefix .'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) );
if ( $unlinked ) {
// now the entry can be deleted
FrmEntry::destroy( $entry_id );
}
}
Automatically delete files
If you would like to delete uploaded files from your site immediately after they are submitted, use this example.
add_action('frm_after_create_entry', 'after_entry_created', 50, 2); //use 50 to make sure this is done very last
function after_entry_created($entry_id, $form_id){
if($form_id == 5){ //change 5 to the ID of your form
$field_id = 25; //change 25 to the ID of the upload field
if(isset($_POST['item_meta'][$field_id])){
if(is_array($_POST['item_meta'][$field_id])){
foreach ($_POST['item_meta'][$field_id] as $p){
if(is_numeric($p))
wp_delete_attachment($p, true);
}
}else if(is_numeric($_POST['item_meta'][$field_id])){
wp_delete_attachment( $_POST['item_meta'][$field_id], true );
}
}
}
}
Insert form data into second database table
add_action('frm_after_create_entry', 'copy_into_my_table', 20, 2);
function copy_into_my_table($entry_id, $form_id){
if($form_id == 4){ //change 4 to the form id of the form to copy
global $wpdb;
$values = array('col_name1' => $_POST['item_meta'][25], 'col_name2' => $_POST['item_meta'][26]);
//replace 25 and 26 with the field ids of the Formidable form. Change col_name to the column names in your table
$wpdb->insert('table_name', $values);
}
}
Decrease an available count in another form
This example assumes you have two forms set up: one for the event and one for reservations. The event form will include a field for the number of available openings. The reservation form will include a Dynamic field to list all the events. This function will drop the number of available openings for an event when it is selected.
If the $seat_count_field uses a field that is selected as a post field, this example will need extra modification in order to update the value in the WordPress post.
add_action('frm_after_create_entry', 'after_entry_created', 30, 2);
function after_entry_created($entry_id, $form_id){
if($form_id == 5){ //change 5 to the ID of your reservations form
global $wpdb;
$reward_ids = $_POST['item_meta'][25]; //change 25 to the ID of your Dynamic dropdown field in your reservations form
$seat_count_field = 15; //change 15 to the ID of the available seats field in the event form
foreach ( (array) $reward_ids as $reward_id ) {
$available = FrmEntryMeta::get_entry_meta_by_field( $reward_id, $seat_count_field, true );
$wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => ( (int) $available-1 ) ), array( 'item_id' => $reward_id, 'field_id' => $seat_count_field ) );
}
}
}
Update or create another entry
Use this code to check if the current user already has an entry in Form B when Form A is submitted. If the user does NOT have an entry in that form, this code will create a new entry in Form B. If they do have an entry in Form B, it will update the entry. This example specifically will populate a field in Form B with the user's total number of submissions in Form A.
add_action('frm_after_create_entry', 'update_or_create_entry', 30, 2);
add_action('frm_after_update_entry', 'update_or_create_entry', 10, 2);
function update_or_create_entry($entry_id, $form_id){
if ( $form_id == 430 ) {//Change 430 to the ID of Form A
global $wpdb;
$form2 = '480';//Change 480 to the ID of Form B
//Get user and their total
$user = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$wpdb->prefix}frm_items WHERE id=%d", $entry_id));
if ( !$user ) {
return;
}
$total = FrmProStatisticsController::stats_shortcode(array('id' => 47914, 'type' => 'count', 'user_id' => $user));//Change 47914 with the ID of the field that you want to total
//See if this user already has an entry in second form
$entry_id = $wpdb->get_var("Select id from {$wpdb->prefix}frm_items where form_id='" . $form2 . "' and user_id=". $user);
if ( $entry_id ) {
//update entry
$wpdb->update( $wpdb->prefix . 'frm_item_metas', array('meta_value' => $total), array('item_id' => $entry_id, 'field_id' => '48262'));//Change 48262 to the ID of the field you want to populate in Form B
} else {
//create entry
FrmEntry::create(array(
'form_id' => $form2,
'item_key' => $user . 'total', //change entry to a dynamic value if you would like
'frm_user_id' => $user,
'item_meta' => array(
48262 => $total, //change 48262 to the ID of the field you want to populate (in Form B)
48269 => $user,//Change 48269 to the ID of the userID field in Form B
),
));
}
}
}
Change 430 to the ID of Form A, 480 to the ID of Form B, 47914 with the ID of the field that you want to total, 48262 to the ID of the field you want to populate in Form B, 48262 to the ID of the field you want to populate (in Form B), and 48269 to the ID of the userID field in Form B
Clear a field value after email is sent
If there are values in your form that you would like included in the email and then removed from your site, you can delete the value.
add_action('frm_after_create_entry', 'after_entry_created', 42, 2);
function after_entry_created($entry_id, $form_id){
if ( $form_id == 5 ) { //change 5 to the ID of your form
FrmEntryMeta::delete_entry_meta($entry_id, 30); // change 30 to your field id
}
}
Change user role after entry submission
Use this code to change a user's role after he/she submits an entry in a specific form.
/**
* This will change an inactive user to a member after they complete their member profile.
*/
add_action('frm_after_create_entry', 'inactive_to_member', 20, 2);
function inactive_to_member($entry_id, $form_id){
if($form_id == 24){ //change 24 to the form id of the form to copy
$new_role = 'member'; //change this to the role users should be granted upon completing form
$user = wp_get_current_user(); //get logged in user
if(!$user) {
return; //don't continue if user doesn't exist
}
$updated_user = (array)$user;
// Get the highest/primary role for this user
$user_roles = $user->roles;
$user_role = array_shift($user_roles);
if ( $user_role == 'administrator' )
return; //make sure we don't downgrade any admins
$updated_user['role'] = $new_role;
wp_update_user($updated_user);
}
}
Add user meta to user
This example adds the id of the entry to a custom field in the user profile.
add_action('frm_after_create_entry', 'add_entry_id_to_user', 30, 2);
function add_entry_id_to_user( $entry_id, $form_id ) {
if($form_id == 24){ //change 24 to the form id of the form to copy
$entry = FrmEntry::getOne($entry_id);
if ( ! $entry->user_id ) {
return; //don't continue if no user
}
update_user_meta( $entry->user_id, 'frm_the_entry_id', $entry_id );
}
}
Add image meta
Use this code to programmatically add an "alt" to files uploaded in a Formidable form. The "alt" will use the name of the uploaded file.
add_action('frm_after_create_entry', 'add_uploaded_file_alt', 30, 2);
function add_uploaded_file_alt( $entry_id, $form_id ) {
if ( $form_id == 5 ) { //replace 5 with the id of the form
// Get all uploaded file attachment IDs
$media_ids = $_POST['item_meta'][519];//Replace 519 with the ID of your file upload field
foreach ( (array)$media_ids as $id ) {
if ( ! $id ) {
continue;
}
// Get file name
$label = basename( get_attached_file( $id ) );
// Add alt
update_post_meta( $id, '_wp_attachment_image_alt', $label );
}
}
}
Create entry in form with repeating section
Use the code below to create an entry in Form B (that has a repeating section) when an entry in Form A (also has a repeating section) is submitted.
add_action('frm_after_create_entry', 'create_repeating_section_entry', 30, 2);
function create_repeating_section_entry($entry_id, $form_id){
if ( $form_id == 5 ) { //replace 5 with the id of Form A
// Format the values for the repeating section
$repeating_values = array();
foreach( $_POST['item_meta'][6804] as $k => $r ) {// Change 6804 to the ID of the repeating section in Form A
if ( $k === 'form' ) {
$repeating_values[ $k ] = 1019;// Change 1019 to the ID of the repeating section child form in Form B
} else if ( is_array( $r ) ) {
foreach ( $r as $i => $v ) {
if ( $i == 6806 ) {// Change 6806 to the ID of a field inside of the repeating section in Form A
$repeating_values[ $k ][12823] = $v;// change 12823 to the ID of a field inside the repeating section in Form B
} else if ( $i == 6807 ) {// Change 6806 to the ID of a field inside of the repeating section in Form A
$repeating_values[ $k ][12824] = $v;// change 12823 to the ID of a field inside the repeating section in Form B
}
}
}
}
// create entry.
FrmEntry::create(array(
'form_id' => 10,// Change 10 to the ID of Form B
'item_key' => $_POST['item_key'], //change entry to a dynamic value if you would like
'item_meta' => array(
12821 => 'test value', //change 12821 to the ID of the field you want to populate (in Form B)
12822 => $repeating_values,//Change 12822 to the ID of the repeating section field in Form B
),
));
}
}
Automatically update a field in another form
Use this code to make sure two fields from two different forms always have the same value stored. For example, when a user updates their Email address in an "Edit Profile" form, then the email address stored in all of that user's entries in a second form will be automatically updated to match the new email address.
Note: Make sure that the receiving field has an original value or it won't be updated.
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 == 113){//Change 113 to the ID of the first form
global $wpdb;
$first_field = $_POST['item_meta'][25]; //change 25 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='112' and user_id=". $user);//Change 112 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' => '6422'));//Change 6422 to the ID of the field to be updated automatically in your second form
}
}
Break post content and View connection
Use this code to break the connection between the post content and the View so you can edit your post through the back-end. Please note that when you break the connection between the post content and a View, then any changes made to the View will not affect the post content.
In the code below, replace 156 with the ID of your form.
add_action('frm_after_create_entry', 'frm_break_post_content_connection', 60, 2);
function frm_break_post_content_connection( $entry_id, $form_id ) {
if ( $form_id == 156 ) {// Replace 156 with the ID of your form
$entry = FrmEntry::getOne( $entry_id );
if ( ! $entry->post_id ) {
return;
}
delete_post_meta( $entry->post_id, 'frm_display_id' );
}
}
Create an entry in another form
Use this code to create an entry in Form B when you submit an entry in Form A. A field in Form B will have the user ID from Form A. Another will have the entry ID of Form A entry. And a final will have the value of another field in Form A. If you use the code as written, the user ID and additional value are treated as required. If they're not present, the entry won't be created. You can remove or comment out code you don't want to use.
add_action('frm_after_create_entry', 'create_entry_after_submission', 30, 2);
function create_entry_after_submission($entry_id, $form_id){
if ( $form_id != 372 ) {//Change 372 to the ID of Form A
return;
}
$form2 = '373';//Change 373 to the ID of Form B
//Get user
if (!isset($_POST['frm_user_id'])){
return;
}
$user = $_POST['frm_user_id'];
//get data
if (!isset($_POST['item_meta'][6614])){ //replace 6614 with the field ID of the Form A value
return;
}
$new_value = $_POST['item_meta'][6614];
//create entry
FrmEntry::create(array(
'form_id' => $form2,
'item_key' => 'entry', //change entry to a dynamic value if you would like
'frm_user_id' => $user,
'item_meta' => array(
6620 => $entry_id, //change 6620 to the ID of the field you want to populate (in Form B) with the entry ID of Form A
6621 => $user,//change 6621 to the ID of the userID field in Form B
6622 => $new_value,//Change 6622 to the ID of a field in Form B you want to populate with a value from Form A
),
));
}
Change 372 for the id of Form A, 373 for the id in Form B, 6614 for the field ID which holds the value in Form A you want to add to Form B, 6620 for the field ID in Form B that stores the Form A entry ID, 6621 for the field ID of the User ID field in Form B, and 6622 for the field ID in Form B that has the value from form A.
Run code when user saves a draft
Start with this example if you want to do something when a user saves a draft instead of submitting a final entry.
add_action('frm_after_create_entry', 'frm_after_save_draft', 30, 2);
add_action('frm_after_update_entry', 'frm_after_save_draft', 30, 2);
function frm_after_save_draft($entry_id, $form_id){
if ( $form_id == 221 ) { //change 221 to the ID of your form
if ($_POST['frm_saving_draft'] == 1) {
// do something here
}
}
}
Change 221 to the id of your current form and insert your code in the do something here section.
Move and rename files
Use values from your entries to organize and rename your file uploads. Before using this, we recommend you try a more simple option.
add_action( 'frm_after_create_entry', 'frm_move_file_and_rename' );
function frm_move_file_and_rename() {
$field_ids = array( 25, 26 ); // change field IDs to the IDs of your file upload fields
foreach ( $field_ids as $field_id ) {
if ( isset( $_POST['item_meta'][ $field_id ] ) ) {
if ( ! frm_filesystem_prepared() ) {
return;
}
$file_ids = array_filter( (array) $_POST['item_meta'][ $field_id ], 'is_numeric' );
foreach ( $file_ids as $file_id ) {
$file_id = absint( $file_id );
$old_source = get_attached_file( $file_id );
$file_name = basename( $old_source );
// change the filename here
$file_name = sanitize_title( $_POST['item_meta'][ 41150 ] ) . '-' . $file_name; // Change 41150 to the id of your file name field. remove this line to leave the filename as is
// set folder name here
$new_folder_name = 'formidable/' . sanitize_title( $_POST['item_meta'][ 41335 ] ); // Change 41335 to the id of the folder name field
$file_info = new FrmCreateFile( array( 'folder_name' => $new_folder_name, 'file_name' => $file_name ) );
frm_create_directories( $file_info );
$destination = $file_info->uploads['basedir'] . '/' . $new_folder_name . '/' . $file_name;
global $wp_filesystem;
if ( $wp_filesystem->move( $old_source, $destination ) ) {
update_attached_file( $file_id, $destination );
}
}
}
}
}
function frm_filesystem_prepared() {
if ( ! is_admin() || ! function_exists( 'get_filesystem_method' ) ) {
include_once(ABSPATH . 'wp-admin/includes/file.php');
}
$access_type = get_filesystem_method();
if ( $access_type === 'direct' ) {
$creds = request_filesystem_credentials( site_url() . '/wp-admin/', '', false, false, array() );
}
return ( ! empty( $creds ) && WP_Filesystem( $creds ) );
}
function frm_create_directories( $file_info ) {
global $wp_filesystem;
$needed_dirs = frm_get_needed_dirs( $file_info );
foreach ( $needed_dirs as $_dir ) {
// Only check to see if the Dir exists upon creation failure. Less I/O this way.
if ( $wp_filesystem->mkdir( $_dir, $file_info->chmod_dir ) || $wp_filesystem->is_dir( $_dir ) ) {
$index_path = $_dir . '/index.php';
$wp_filesystem->put_contents( $index_path, FS_CHMOD_FILE );
}
}
}
function frm_get_needed_dirs( $file_info ) {
$dir_names = explode( '/', $file_info->folder_name );
$needed_dirs = array();
$next_dir = '';
foreach ( $dir_names as $dir ) {
$next_dir .= '/' . $dir;
$needed_dirs[] = $file_info->uploads['basedir'] . $next_dir;
}
return $needed_dirs;
}
Save the entry ID in a field
This code allows you to save the entry ID of the current entry in one of its fields.
add_action('frm_after_create_entry', 'frm_add_entry_id', 42, 2);
function frm_add_entry_id($entry_id, $form_id){
if ( $form_id == 221 ) { //change 221 to the ID of your form
FrmEntryMeta::add_entry_meta( $entry_id, 1819, "", $entry_id);//change 1819 to the ID of the field in which you want to store the entry ID
}
}
Change 221 to the id of your current form and 1819 to the id of the field where you'd like to store the entry ID.
Notes:
- For this code to work properly, the field that stores the entry ID must be empty. It shouldn't have a default value, and users shouldn't be able to enter a value into it.
- This code should only be used with the frm_after_create_entry hook, not the frm_after_update_entry hook.
Update field in another form using entry id
This code allows you to update a field in your main form to a set value, like "paid" or "approved," when a person fills out a second form. The second form should have a field that has the id of the entry to be updated.
This code will send email notifications in your main form that are triggered on entry update. If you don't want this, you can remove the last three lines of the code.
add_action('frm_after_create_entry', 'frm_update_entry_in_other_form', 30, 2);
function frm_update_entry_in_other_form($entry_id, $form_id){
if ( $form_id !== 997 ) { //Change 997 to the ID of your update form
return;
}
$entry_id = $_POST['item_meta'][9353]; //change 9353 to the ID of the field in your update form that has the entry id
$field_id = 9352; // change 9352 to the ID of the field in your main form that's to be updated
$new_value = 'Approved';// change 'Approved' to the value you want to set the field in your main form
$added = FrmEntryMeta::add_entry_meta( $entry_id, $field_id, null, $new_value );
if ( ! $added ) {
FrmEntryMeta::update_entry_meta( $entry_id, $field_id, null, $new_value );
}
// Remove the following lines if you don't want to trigger emails.
$entry = FrmEntry::getOne( $entry_id, true );
$form = FrmForm::getOne( $entry->form_id );
FrmFormActionsController::trigger_actions('update', $form, $entry, 'email');
}
Notes
Change:
- 997 to the id of the form you're using to update your main form.
- 9353 to the id of the field in the update form that has the entry id in it.
- 9352 to the id of the field in your main form that you're updating
- 'Approved' to the value to which you want the field in the main form tto be updated
Capture timestamp
This example will capture timestamp for when the entry is submitted.
add_action( 'frm_after_create_entry', 'my_custom_function', 30, 2 );
function my_custom_function( $entry_id, $form_id ){
$entry = FrmEntry::getOne( $entry_id );
// Get the created_at date in a UNIX timestamp
$timestamp = strtotime( $entry->created_at );
}
Save api response for repeater
This example will allow you to create new rows in a repeater via the Formidable API.
add_action( 'frm_after_create_entry', 'frm_save_api_response_for_repeater', 10, 2 );
function frm_save_api_response_for_repeater( $entry_id, $form_id ) {
$target_child_form_id = 99; // change 99 to the ID of the child form
if ( $target_child_form_id == $form_id ) {
$repeater_field_id = 123; // change 123 to the repeater field ID
$entry = FrmEntry::getOne( $entry_id );
$current_value = FrmEntryMeta::get_entry_meta_by_field( $entry->parent_item_id, $repeater_field_id );
$current_value = maybe_unserialize( $current_value );
$current_value = (array) $current_value;
$current_value[] = (int) $entry->id;
FrmEntryMeta::update_entry_meta( $entry->parent_item_id, $repeater_field_id, null, $current_value );
}
}
This example above is an alternative to this other example using the frmapi_post_response hook
Save the entry Key in a field
This code allows you to save the entry Key of the current entry in one of its fields.
add_action( 'frm_after_create_entry', 'frm_add_entry_id', 42, 2 );
function frm_add_entry_id( $entry_id, $form_id ) {
if ( $form_id == 221 ) { //change 221 to the ID of your form
$entry = FrmEntry::getOne( $entry_id );
$key = $entry->item_key;
FrmEntryMeta::add_entry_meta( $entry_id, 1819, "", $key);//change 1819 to the ID of the field in which you want to store the entry Key
}
}
Change 221 to the id of your current form and 1819 to the id of the field where you'd like to store the entry Key.
Notes:
- For this code to work properly, the field that stores the entry Key must be empty. It shouldn't have a default value, and users shouldn't be able to enter a value into it.
- This code should only be used with the frm_after_create_entry hook, not the frm_after_update_entry hook.
Add gallery to WooCommerce product
This code allows you to add a gallery to the WooCommerce product.
add_action('frm_after_create_entry', 'frm_add_gallery_to_product', 60, 2);
function frm_add_gallery_to_product( $entry_id, $form_id ) {
if ( $form_id == 1705 ) {// Replace 1705 with the ID of your form
$entry = FrmEntry::getOne( $entry_id );
if ( ! $entry->post_id ) {
return;
}
update_post_meta($entry->post_id, '_product_image_gallery', implode( ',', $_POST['item_meta'][39744] )); //change 39744 to the ID of your gallery file upload field
}
}
Create an entry for each user
This code can be used to create an entry for each user in a directory or other form.
Submitting a separate form (the Trigger form) will trigger the creation of entries for users in the directory form. The Trigger form doesn't need to have any fields. Submitting the form is just a convenient way to trigger the entry creation when you want.
The Trigger form can be submitted multiple times. If a user doesn't already have an entry in the directory form, a new one will be created.
After the code is added to the site, when a new user is registered on the site, an entry in the directory form will automatically be created.
If a user is deleted from the site, that user's entry in the directory form will be deleted.
add_action('frm_after_create_entry', 'frm_create_entry_for_each_user', 30, 2);
function frm_create_entry_for_each_user( $entry_id, $form_id ) {
global $wpdb;
if ( $form_id != 527 ) { //Change 527 to the id of the Trigger form
return;
}
$directory_form = '526'; // Change 526 to the id of the directory form.
$entry_table = $wpdb->prefix . "frm_items";
$query = "SELECT id from $wpdb->users users WHERE NOT EXISTS ( SELECT user_id FROM $entry_table entries WHERE form_id = $directory_form AND users.id = entries.user_id )";
$user_ids = $wpdb->get_col( $query );
if ( ! $user_ids ) {
return;
}
foreach ( $user_ids as $user_id ) {
frm_create_entry_for_user( $directory_form, $user_id );
}
unset( $user_id );
}
add_action( 'user_register', 'frm_create_directory_entry_for_user', 10, 1 );
function frm_create_directory_entry_for_user( $user_id ) {
$directory_form = '526'; // Change 526 to the id of the directory form.
frm_create_entry_for_user( $directory_form, $user_id );
}
function frm_create_entry_for_user ( $directory_form, $user_id ){
FrmEntry::create( array(
'form_id' => $directory_form,
'item_key' => 'entry', // Change entry to a dynamic value if you would like.
'frm_user_id' => $user_id,
'item_meta' => array(
4286 => $user_id, // Change 4286 to the id of the User ID field in the directory form
),
) );
}
add_action( 'delete_user', 'frm_destroy_user_entry' );
function frm_destroy_user_entry( $user_id ){
global $wpdb;
$directory_form = '526'; // Change 526 to the id of the directory form.
$entry_table = $wpdb->prefix . "frm_items";
$query = "SELECT id FROM $entry_table WHERE user_id = $user_id AND form_id = $directory_form";
$entry_ids = $wpdb->get_col( $query );
if ( ! $entry_ids ) {
return;
}
foreach ( $entry_ids as $entry_id ){
FrmEntry::destroy( $entry_id );
}
}
- Change 527 to the id of the Trigger form.
- Change 526 to the id of the directory form, in three places.
- Change 4286 to the id of the User ID field in the directory form.
Save the ID of created post in a field
add_action('frm_after_create_entry', 'save_post_id', 60, 2);
function save_post_id( $entry_id, $form_id ) {
if ( $form_id == 341 ) {// Replace 341 with the ID of your form
$entry = FrmEntry::getOne( $entry_id );
if ( ! $entry->post_id ) {
return;
}
FrmEntryMeta::add_entry_meta( $entry_id, 1290, "", $entry->post_id); // Replace 1290 with the ID of the field where the postID should be saved
}
}