• Resolved Fenga

    (@fungzhao)


    Hi,

    I have created a form in forminator and in the User Role I want to use the Assign Role Conditionally. As per the screenshot below:
    https://snipboard.io/Hm4tpX.jpg

    I was wondering if its possible to connect multiple conditions together? Such as if FirstName is Michael and Surname is Dean then assign a role

    Thanks

    Fung

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Predrag – WPMU DEV Support

    (@wpmudev-support1)

    Hi @fungzhao,

    I’m afraid there’s no option at the moment to change this and the default behavior is to apply the role if any of the rules match.

    I did create a feature request for our devs to add an option to choose from applying role IF ANY or IF ALL of the rules apply.

    Cheers,
    Predrag

    Thread Starter Fenga

    (@fungzhao)

    Hi @wpmudev-support1

    Thank you for the reply and the feature request, that would be much appreciated. As a workaround I was thinking I can set a hidden field which I will populate by evaluating the form data myself and use the rules with the hidden field instead to the role.

    Do you know of any hooks I can use to pull the form data before submission and then set the hidden field value myself?

    Thanks

    Fung

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @fungzhao

    You can use this:

    Set a hidden field > Custom value and add any custom value to it by default.

    The below hook will update it, the above shared case is an example on using a custom email field:

    <?php 
    
    add_filter( 'forminator_field_hidden_field_value', function( $value ){
    
    	if( $value === 'custom_email' ){
    		$post_id = get_queried_object_id();
    		$custom_email = get_post_meta( $post_id, 'custom_email', true );
    		$value = $custom_email;
    	}
    	return $value;
    } );

    Let us know if you have any additional questions.
    Best Regards
    Patrick Freitas

    Thread Starter Fenga

    (@fungzhao)

    Hi,

    Thank you for the response.

    I was wondering if there is a list of filter and hooks that is documented that I can refer to? I will try the code above and see how I go.

    Thanks

    Thread Starter Fenga

    (@fungzhao)

    Hi,

    I was also wanting to potentially to run some code before teh form is submitted, would the following be the correct hook to us? ‘forminator_custom_form_before_save_entry’, is there any sample code on how to use the hook if it is?

    Thanks

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello @fungzhao

    I’m afraid there’s no complete documentation of hooks and filters.

    A better hook to handle that is the forminator_cform_user_registered action, which runs after the user creation.

    You can find a sample here:
    https://gist.github.com/wpmudev-sls/d759fee64e233af23c19a848d4207a07
    in where you should probably replace wp_set_password() and do something like:

    $wp_user_object = new WP_User( $user_id );
    $wp_user_object->set_role( 'THEROLE' );

    depending on what’s stored in $submitted_data.

    Warm regards,
    Dimitris

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @fungzhao ,

    We haven’t heard from you for several days now, so it looks like you don’t have more questions for us.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Set multiple conditions to apply role’ is closed to new replies.