• Resolved pstidsen

    (@pstidsen)


    Hi there,

    I have a form with user registration. The user role is set up to be set based on some conditions (several, complex rules). Is it possible to show the user role of the newly registered user at the submission page along with the entered username, name etc.?

    And moreover: Is it possible to change that user role directly from the submission page? That would be awesome!

    Best Regards,
    Peter

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @pstidsen,

    I hope you are doing well today!

    We are checking your request with our SLS (Second Line Support) team if it is possible to provide a workaround or custom code to achieve those requests and will inform you accordingly.

    Thanks for the patience while we are looking into the issue.

    Kind regards,
    Zafer

    Thread Starter pstidsen

    (@pstidsen)

    Hi Zafer,

    Thanks for writing back. I am looking forward to hearing further.

    My idea was to maybe insert a hidden field and then filter the shown field value in the submissions page if possible..

    Since the form has an e-mail field, the entry has information that can be used to get the user information.

    Looking forward to hearing from you.

    Best Regards,
    Peter B. Stidsen

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @pstidsen,

    Could you please check and see whether the following snippet helps?

    <?php
    
    add_action( 'forminator_cform_user_registered', 'wpmudev_handle_user_role', 10, 4 );
    function wpmudev_handle_user_role( $user_id, $custom_form, $entry, $pass ) {
        if ( 842 != $custom_form->id ) { // Please change the form ID.
            return;
        }
    
        $user_data = get_userdata( $user_id );
        if ( ! empty( $user_data->roles ) ) {
            $entry_meta = array(
                array(
                    'name' => 'hidden-1',
                    'value' => $user_data->roles[0]
                )
            );
    
            Forminator_API::update_form_entry( $custom_form->id, $entry->entry_id, $entry_meta );
        }
    }

    You’ll make sure to update the 842 number in the code with your form ID and also make sure to update the field ID of the Hidden field in here:
    'name' => 'hidden-1',

    If the Hidden field added in your form has hidden-2 as its field ID, then the above line will change as follows:
    'name' => 'hidden-2',

    You can implement the above snippet using mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    I gave a quick test and the it works when tested and does display tho role for the submissions.

    Please do check and see whether that helps.

    Kind Regards,

    Nithin

    Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi again @pstidsen,

    And moreover: Is it possible to?change?that user role directly from the submission page? That would be awesome!

    Please also note that this is out of scope of support that we can provide here due to the customization required and we suggest you to hire a developer to achieve this.

    Kind regards,
    Zafer

    Thread Starter pstidsen

    (@pstidsen)

    Hi Nithin and Zafer,

    That snippet did indeed help a lot! Thank you for your awesome support!

    A sub question: Is it possible to filter the entry meta values in the submissions page? That will open for a lot of flexibility.

    Best Regards,
    Peter

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @pstidsen

    This should be possible by default. On the Submissions page choose filters and select only that meta which you would like to see. At the end of the filters, you can see the section “Display Fields”. Select “Specified Fields” and choose the one that you want to see.

    https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#submission-filters

    Kind Regards,
    Kris

    Thread Starter pstidsen

    (@pstidsen)

    Hi Kris,

    Sorry for the confusion. I mean more a filter hook like this:

    add_filter('forminator_meta_value', 'custom_filter_value', 10, 2);
    
    function custom_filter_value($value, $entry_id){
    if ($something){
    $value = 'some value';
    }
    
    return $value;
    }

    Is there something like this example code?

    Hi @pstidsen,

    Hope this message finds you well.

    Guessing you want to filter submissions by default with a certain value, I did look for similar requests and I was not able to find any.

    However, I notified our Second Line Support about it, once we get a reply from them we will let you know.

    Also, note the submission page does have a Keyword feature.

    Best regards,
    Laura

    Hi @pstidsen,

    We got feedback from our devs, and they share this code:

    add_filter('forminator_entry_meta_value_to_string', 'custom_filter_value', 10, 5);
    
    function custom_filter_value($string_value, $field_type, $meta_value, $allow_html, $truncate) {
        // Put your own rules here
        if ($condition) {
            $string_value = 'what you want it to be instead';
        }
        return $string_value;
    }

    Let us know the results.

    Best regards,
    Laura

    Thread Starter pstidsen

    (@pstidsen)

    Hi Laura,

    Thanks a lot. Unfortunately, that does not help that much because the entry/submission ID or object is not present in the filter. I would need that for my goal.

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @pstidsen

    I pinged our SLS Team once again to review this once more. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Hi @pstidsen,

    Sorry for our delay, our Devs shared this with you.

    apply_filters( 'forminator_custom_form_entries_iterator', $iterator, $entry );

    Works on the entry page only and has the $entry object. You access the entry ID like this $entry->entry_id.

    Let us know the results.

    Best regards,
    Laura

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @pstidsen

    We haven’t heard from you in a while, I’ll go and mark this thread as resolved. If you have any additional questions or require further help, please let us know!

    Kind Regards,
    Kris

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Show user rule at admin submission page’ is closed to new replies.