• Resolved joashenrique

    (@joashenrique)


    Hello everything is fine?

    Is it possible to notify all WordPress users when a form is submitted?

    I know that it is possible to register all existing e-mails from users of my site, but it would be more practical if a query parameter were the currently registered users and already notified everyone. That way I wouldn’t have to register a new email on the form when a new user registers on my site.

Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @joashenrique

    I hope you are doing well today.

    I’m a little bit confused by your query. In this first place it seems you ask for email notification for all users when “some” form is submitted.

    Is there any reason why 10,100,1000 users from your site should know that some user submitted a form?

    Only example which comes to my mind is that you have a form with post data field and you would like to notify users about new post on the site.

    Taking into account above example I’m not able to connect dots with your additional request -> “That way I wouldn’t have to register a new email on the form when a new user registers on my site.”

    Can you fully explain whole idea so that we could be on the same page?

    Kind Regards,
    Kris

    Thread Starter joashenrique

    (@joashenrique)

    Hello everything is fine?

    This form serves as a business information among users. The idea is that all users look for dentor when someone does business with each other, that is, I bought something from some user and I need to fill out this form to notify everyone that we did business. The idea is to show users that being part of my team is something that always promotes business between people. We have something similar to a community of entrepreneurs who are doing business with each other and we need this notification to be forwarded to everyone to strengthen the idea that everyone is doing business, you know?

    Because of this I need that when someone fills out a form everyone is notified.

    Because of this, I need that when someone fills out a form, all users who have an account on the site or have a specific attribution (Subscriber or Seller) are notified.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @joashenrique

    Thanks for response!

    This makes sense to me but here is the thing:

    Forminator was never designed as such a “notification center”. It can send multiple notifications at once but there are a few issues related here:

    – you can only fetch addresses dynamically from form fields and other need to be manually “fixed” defined in notification setting
    – it has no any mechanisms to send massive e-mails in a “queue” – it wouldn’t use AJAX or CRON tasks to e.g. send number of notifications in bulk, then wait and send another set and so on

    Therefore if there are more than few e-mails it can lead to various issues such as sometimes overloading server resources, delivery issues and even triggering some security features on the hosting/mail server due to such “bulk mailing”.

    There could be relatively easily custom code created that would automatically add all the users e-mails to “CC” or “BCC” or even just a regular recipient list but again – if there’s a lot of users, that is more than likely to result in some issues sooner or later.

    The best course of action here would be to use 3rd-party solution for sending such e-mails. For example, you could make sure that all your users are added as subscribers to some designated MailChimp (or similar service) group and then:

    – use Forminator’s “webhook” integration to connect form to Zapier, Make, Integrately or similar service
    – then also integrate that service with MailChimp (or similar service)

    This way data from form could be sent via webhook to the “middleman” and then that “middleman” service would trigger MailChimp or similar to send notofication.

    Another option is to use some dedicated/specialized mailing plugin on the site and try to integrate it with Forminator – but that would in most cases require some additional custom code and I’m not able to tell upfront how much we could help with tis. It would depend on that plugin and what kind of hooks/APIs it provides.

    Kind regards,
    Adam

    Thread Starter joashenrique

    (@joashenrique)

    Hello everything is fine?

    Legal. I will do this!

    Also, note that when the form is integrated with Google Sheet, when there are checkbox or checkbox fields the field is filled as “one” in Google Sheet. How can this be fixed?

    Also, is it possible to display the list of users on the Fomrinator form? Something like indicating which user you did business with.

    Today I have to update manually, but it would be interesting to automatically arrange users based on their roles or id.

    Example: https://ibb.co/xj1Vw45

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @joashenrique

    Thanks for response!

    Also, note that when the form is integrated with Google Sheet, when there are checkbox or checkbox fields the field is filled as “one” in Google Sheet. How can this be fixed?

    Please go to the “Settings” page of a give form and you’ll find the “Multiple Option Value” setting there. It affects how the data is stored/handled in case of select/radio/checkbox fields. You can switch it between “Option values” (default) and “Option labels”. This should help. Note though: it will not affect previous submissions.

    Also, is it possible to display the list of users on the Fomrinator form? Something like indicating which user you did business with.

    Out of the box there’s no such option. It may be possible with a bit of additional custom code but I’m not quite sure how would you like it to work.

    I can see the sheet that you shared as example but since I don’t know your workflow and goals, it’s not quite understandable for me.

    I mean – you want to display just a “static” list of all user accounts on site (e.g. by username) or some other data/form? Or you mean like – including information on which user submitted the form right in submission (so it would be included in Google Sheet)? Or yet another case?

    If you could, please, explain it a bit more (an example case scenario would be helpful) we could look into it and check if it would really be doable.

    Best regards,
    Adam

    Thread Starter joashenrique

    (@joashenrique)

    Hello everything is fine?

    The idea of ??the worksheet uses checkbox and select it worked. Now the data appears in the worksheet after submitting the form.

    Regarding the list of users, I would like to display only a “static” list of all user accounts on the site (e.g. by username). It would be even better if I could restrict the display of these users to only a certain role, that is, only users who have the role “Subscriber” appear in this list.

    That way, when someone fills out the form indicating who they did business with, the static list of users already appears on the form so that the person can indicate which user they did business with.

    Hi @joashenrique,

    Hope this message finds you well and thanks for the update.

    Regarding the list of users, I would like to display only a “static” list of all user accounts on the site (e.g. by username). It would be even better if I could restrict the display of these users to only a certain role, that is, only users who have the role “Subscriber” appear in this list.

    By list you mean a dropdown or select where the users with specific Subscriber roles are pre-populated?

    Please let us know.

    Best regards,
    Laura

    Thread Starter joashenrique

    (@joashenrique)

    Hello everything is fine?

    I imagine a drop-down list containing the names of all users registered on the site, that is, when a new user registers on the site, their name will automatically appear in this list.

    For the display rule for this list, as a suggestion, it would be interesting to filter which users would appear in this list. For example: only users who are Subscribers, Authors or Editors.

    I even believe that because it is an extensive list, taking into account that it will display users registered on the site, it could be through the “select” tool already present in Forminator. Because the box would make the form too long.

    Hi @joashenrique,

    Thanks for the clarification.

    Our Developers provided this mu-plugin, to fill or populate the users by display_name and by role into a {select-x} field.

    Note that you might need to replace your own form ID and the roles you want to display.

    add_filter( 'forminator_cform_render_fields', function( $wrappers, $model_id ) {
    	//Replace your Form ID
        if ( $model_id != 26 ) {
            return $wrappers;
        }
    
        $select_fields_data = array(
            'select-1' => 'users',
        );
    
        foreach ( $wrappers as $wrapper_key => $wrapper ) {
            if ( ! isset( $wrapper[ 'fields' ] ) ) {
                continue;
            }
    
            if ( isset( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) && ! empty( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) ) {
    			//Add the user roles in the array and the field you want to display
    	    	$users = get_users( array( 'role__in' => array( 'Subscriber' ), 'fields' => array( 'display_name' ) ) );;
                if ( ! empty( $users ) ) {
                    $new_options = array();
    	        	$user_names = array();
                    foreach( $users as $u ) {
                        $new_options[] = array(
                            'label' => $u->display_name,
                            'value' => $u->display_name,
                            'limit' => '',
                            'key'   => forminator_unique_key(),
                        );
    					$user_names['options'] = $new_options;
                    }
    				$select_field = Forminator_API::get_form_field( $model_id, $wrapper['fields'][0]['element_id'], true );
    				if ( $select_field ) {
    					Forminator_API::update_form_field( $model_id, $wrapper['fields'][0]['element_id'], $user_names );
    					$wrappers[ $wrapper_key ][ 'fields' ][ 0 ][ 'options' ] = $new_options;
    				}
                }
            }
        }
    
        return $wrappers;
        
    },10,2);

    You will find how to add mu-plugin at this link

    Let us know if you require additional assistance.

    Best regards,
    Laura

    Thread Starter joashenrique

    (@joashenrique)

    Hello everything is fine?

    Should I add the {select-x} parameter somewhere? If not, how will you have the mu-plugin information in the form whose ID I indicated in the mu-plugin?

    Accessing the form editor -> HTML Tool and adding {select-x}?

    Thread Starter joashenrique

    (@joashenrique)

    Plugin PHP file:

    <?php
    /**
     * Plugin Name: MU-PLUGINS
     * Plugin URI: https://agendacuritibana.com.br/
     * Description: BOX para carregamento de campos.
     * Version: 1.0.0
     * Author: Agenda Curitibana
     **/
    
    function wpmudev_hosting_enqueue_js()
    {
        wp_enqueue_script( 'wpmudev-hosting', plugin_dir_url( __FILE__ ) . 'wpmudev-hosting', array( 'jquery' ), '1.0', true );
    
            $script_data = array(
            'forminator_nonce' => wp_create_nonce( 'forminator_nonce' ),
            'form_id' => 7993, 
        );
    
        wp_localize_script( 'wpmudev-hosting', 'forminator_data', $script_data );
    }
    add_action('wp_enqueue_scripts', 'wpmudev-hosting');

    <font style=”vertical-align: inherit;”><font style=”vertical-align: inherit;”>Plug-in Javascript:</font></font>

    add_filter( 'forminator_cform_render_fields', function( $wrappers, $model_id ) {
            //Replace your Form ID
        if ( $model_id != 7993 ) {
            return $wrappers;
        }
    
        $select_fields_data = array(
            'select-1' =&gt; 'users',
        );
    
        foreach ( $wrappers as $wrapper_key =&gt; $wrapper ) {
            if ( ! isset( $wrapper[ 'fields' ] ) ) {
                continue;
            }
    
            if ( isset( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) &amp;&amp; ! empty( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) ) {
                            //Add the user roles in the array and the field you want to display
                    $users = get_users( array( 'role__in' =&gt; array( 'Subscriber' ), 'fields' =&gt; array( 'display_name' ) ) );;
                if ( ! empty( $users ) ) {
                    $new_options = array();
                            $user_names = array();
                    foreach( $users as $u ) {
                        $new_options[] = array(
                            'label' =&gt; $u-&gt;display_name,
                            'value' =&gt; $u-&gt;display_name,
                            'limit' =&gt; '',
                            'key'   =&gt; forminator_unique_key(),
                        );
                                            $user_names['options'] = $new_options;
                    }
                                    $select_field = Forminator_API::get_form_field( $model_id, $wrapper['fields'][0]['element_id'], true );
                                    if ( $select_field ) {
                                            Forminator_API::update_form_field( $model_id, $wrapper['fields'][0]['element_id'], $user_names );
                                            $wrappers[ $wrapper_key ][ 'fields' ][ 0 ][ 'options' ] = $new_options;
                                    }
                }
            }
        }
    
        return $wrappers;
    
    },10,2);
    
    if (typeof forminator_data !== 'undefined') {
        var formId = forminator_data.form_id;
        var nonce = forminator_data.forminator_nonce;
    
        console.log('ID do formulário: ' + 7993);
    

    I made this application here, but unfortunately it didn’t work.

    Should an option appear in the Form Editor?

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @joashenrique,

    I am a bit confused about the code that you provided in the previous response. Could you kindly offer a more detailed explanation to help me better understand it?

    Based on the code we’ve supplied, all you need to do is replace “select-1” with the actual select field ID from your form where you want the user names to populate.

    Reference: https://ibb.co/C6VCSzh

    I trust that this clarifies any confusion. If you require any additional assistance, please don’t hesitate to reach out to us.

    Kind Regards,
    Nebu John

    Thread Starter joashenrique

    (@joashenrique)

    Hello everything is fine?

    When adding the code in wp-content -> mu-plugins -> wpmudev-hosting -> wpmudev-hosting.js unfortunately the form still doesn’t work correctly

    add_filter( 'forminator_cform_render_fields', function( $wrappers, $model_id ) {
    	//Replace your Form ID
        if ( $model_id != 7993 ) {
            return $wrappers;
        }
    
        $select_fields_data = array(
            'select-4' => 'users',
        );
    
        foreach ( $wrappers as $wrapper_key => $wrapper ) {
            if ( ! isset( $wrapper[ 'fields' ] ) ) {
                continue;
            }
    
            if ( isset( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) && ! empty( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) ) {
    			//Add the user roles in the array and the field you want to display
    	    	$users = get_users( array( 'role__in' => array( 'Subscriber' ), 'fields' => array( 'display_name' ) ) );;
                if ( ! empty( $users ) ) {
                    $new_options = array();
    	        	$user_names = array();
                    foreach( $users as $u ) {
                        $new_options[] = array(
                            'label' => $u->display_name,
                            'value' => $u->display_name,
                            'limit' => '',
                            'key'   => forminator_unique_key(),
                        );
    					$user_names['options'] = $new_options;
                    }
    				$select_field = Forminator_API::get_form_field( $model_id, $wrapper['fields'][0]['element_id'], true );
    				if ( $select_field ) {
    					Forminator_API::update_form_field( $model_id, $wrapper['fields'][0]['element_id'], $user_names );
    					$wrappers[ $wrapper_key ][ 'fields' ][ 0 ][ 'options' ] = $new_options;
    				}
                }
            }
        }
    
        return $wrappers;
        
    },10,2);
    Thread Starter joashenrique

    (@joashenrique)

    Hi @joashenrique,

    Thanks for the update.

    Could you please let us know which User role you want to fill? In this line it does get Subscribers, could you try adding Administrator too?

    $users = get_users( array( 'role__in' => array( 'Subscriber', 'Administrator' ), 'fields' => array( 'display_name' ) ) );;

    Let us know the results.

    Best regards,
    Laura

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Notify all users’ is closed to new replies.