Add or remove WP role based on form checkbox/radio button value

By: Sean Jones | Asked: 09/21/2025
ForumsCategory: General questionsAdd or remove WP role based on form checkbox/radio button value
Sean Jones asked 4 months ago

Scenario:

Form ID = 24

Checkbox in form: Do you own a studio? Option: YES

Action needed:

If the user has selected YES that they own a studio, I'd like to then add the role STUDIO to their WP profile.  Conversely, if YES is unchecked, I'd like to remove the STUDIO role if it exists for that user.

I found the code below as a start, but I am not sure where to go from here.  I am new to PHP as I have not worked with it much in my development career.  Playing catch up here.

Also, how would I invoke the snippet upon form update submission??

 

add_action( 'frm_after_create_entry', 'inactive_to_member', 20, 2 );
function inactive_to_member($entry_id, $form_id) {
if ( $form_id == 24 ) { // form id of the form to copy

$user = wp_get_current_user(); //get logged in user
if ( !$user ) {
return; //don't continue if user doesn't exist
}

// Get user roles
$user_roles = $user->roles;

NEED CONDITIONAL LOGIC HERE

//If studio checkbox is checked, ensure studio role is present
//if ( !in_array( 'studio', $user_roles ) ) {
// Add Role Studio
$user->set_role( 'studio' );
}

//If studio checkbox is unchecked, ensure studio role is not present
//if ( in_array( 'studio', $user_roles ) ) {
// Add Role Studio
$user->remove_role( 'studio' );
}
}
}

1 Answers
Rob LeVineRob LeVine Staff answered 4 months ago

For updating use frm_after_update_entry, which is analogous to frm_after_create_entry:
add_action( 'frm_after_create_entry', 'inactive_to_member', 20, 2 );
add_action( 'frm_after_update_entry', 'inactive_to_member', 20, 2 );
function inactive_to_member($entry_id, $form_id) {
...

For the conditional logic: you want to get the field value from the entry and use that for comparison, e.g., $checkbox_value = FrmEntryMeta::get_entry_meta_by_field($entry_id, );

For general PHP issues, I suggest reaching out to a developer, as this is a Formidable support forum
https://formidable-masterminds.com/developers-directory/
You can find someone to mentor you on your journey

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
crossarrow-right