This hook allows you to do something with the data entered in a form after it is updated.
Usage
add_action('frm_after_update_entry', 'after_entry_updated', 10, 2);
Parameters
- $entry_id (integer)
- $form_id (integer)
Examples
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.
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 } }
Change a user's role
Change a user's role with a dropdown or radio field. Replace 41 with the ID of your form, replace 1775 with the ID of the userID field in the form, and replace 1134 with the ID of the role dropdown or radio field.
add_action('frm_after_update_entry', 'update_user_role', 10, 2); function update_user_role($entry_id, $form_id){ if ( $form_id == 41 ) { $userid = $_POST['item_meta'][1775];// 1775 is the ID of the userID field $role = $_POST['item_meta'][1134];// 1134 is the ID of the role dropdown if ( $userid && $role ) { $user = get_userdata( $userid ); if ( $user && ! $user->has_cap('administrator') ) { $user->set_role( $role ); } } } }
If you would like to add your own example, click here.
Have something to add?
Click here to provide feedback on this page.