skip to Main Content

I am working with JetEngine forms and i need to add a dropdown of users to select from in one of the form.

is there any way to do this? i dont see any field type of users and also for the select option. if i choose filled dynamicly i have some pre build functions to get the data but none for the users?

How can I set this dropdown or build a function to be show as one of the dynamiclly generated options?

I have not found much on serching this issue and not in their documentation

2

Answers


  1. Chosen as BEST ANSWER

    As i did not find much info on the web, and there is no real good documentation for the JetEngine Plugins i started digging in the plugins' code. I found that the best solution for me was to create my own form generator - that would give me a custom function to select from when creating a new select field in the form builder.

    This is the code i used for creating the custom generator:

    add_filter( 'jet-form-builder/forms/options-generators', 'my_jet_form_custom_option_generator' ,10, 1);
    add_filter( 'jet-engine/forms/options-generators', 'my_jet_form_custom_option_generator' ,10, 1);
    
    function my_jet_form_custom_option_generator($instances) {
        require(plugin_dir_path(__FILE__). '/jetBuilder/generators/get-users.php');
        $instances[] = new Jet_Form_BuilderGeneratorsGet_Users();
        return $instances;
    }
    

    And this is the basic structure of the actual get-users generator:

    namespace Jet_Form_BuilderGenerators;
    
    require_once(WP_PLUGIN_DIR.'/jetformbuilder/includes/generators/base.php'); 
    
    
    class Get_Users extends Base {
    
        /**
         * Returns generator ID
         *
         * @return string
         */
        public function get_id() {
            return 'my_generator;
        }
    
        /**
         * Returns generator name
         *
         * @return string
         */
        public function get_name() {
            return __( 'My Cool Custom Generator', '' );
        }
    
        /**
         * Returns generated options list
         *
         * @param $args
         *
         * @return array
         */
        public function generate( $args ) {
    
            global $wpdb;
                    
            // this is a dummy SQL....
            $sql = "SELECT {$wpdb->users}.user_email, {$wpdb->users}.display_name, {$wpdb->users}.ID, {$wpdb->usermeta}.meta_value
                FROM {$wpdb->users} INNER JOIN {$wpdb->usermeta} ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id)
                WHERE 1=1 "; // CHANGE QUERY FOR YOUR NEEDS....
    
            $result = array();
            
            $table  = $wpdb->users;
            $rows   = $wpdb->get_results(
                                
                $wpdb->prepare( $sql , $field),
                ARRAY_A
            );
    
            if ( empty( $rows ) ) {
                return $result;
            }
            
            $result[] = array(
                    'value' => 0,
                    'label' => '-----------',
                );
    
            foreach ( $rows as $row ) {
                $result[] = array(
                    'value' => $row['ID'],
                    'label' => $row['display_name'],
                );
            }
    
            return $result;
    
        }
    
    }
    

    Hope this helps...


  2. There is an alternative way of doing it without code as they introduced a dynamic function to pull the user list via query builder.

    Detail explanation here https://youtu.be/v3QR3824F4Y?t=420

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search