PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Hide form for users that are not logged in

  1. There are certain forms that I don't want people to fill out if they're not logged in, so I've put this in as the function for the gform_pre_render_{id} filter:

    function need_login_filter($form)
            {
                if(!is_user_logged_in()) {
                    $newForm=array(
                        'title' => 'You need to log in',
                        'description'    => 'You have to log in to access this item'
                        )
                    );
                    $form=$newForm;
                }
                return $form;
            }

    Which works great for putting up my message, but the submit button is still there. I added 'button' rules to the form object, but when I do, the whole form disappears (including my changed text):

    $newForm=array(
                        'title' => 'You need to log in',
                        'description'    => 'You have to log in to access this item',
                        'button'    => array(
                            'conditionalLogic' => array(
                                'actionType' => 'show',
                                'logicType' => 'all',
                                'rules' => array(
                                    'fieldId' => 0,
                                    'operator' => 'isnot',
                                    'value'     => 'jibberish'
                                )
                            )
                        )
                    );

    So what's the best way to go about doing this? I could wrap it in a shortcode to hide the form based on membership, but I've got a few other things set up that require me to take care of this internal to GravityForms.

    Posted 12 years ago on Wednesday November 30, 2011 | Permalink
  2. If you don't want a form to be visible if a user is not logged in there is a Form Settings specifically for this that lets you disable the form unless the user is logged in.

    See this screenshot, specifically the last option:

    http://dl.dropbox.com/u/185347/Slingshot/Pictures/Screen%20Shot%202011-11-30%20at%205.55.18%20PM.png

    That option also let's you display a message instead of the form if the user that is browsing the page is not logged in. The message also supports shortcodes. So you could control which form they see by inserting a shortcode for a different Gravity Form in the message for the "Require user to be logged in" setting.

    This would allow you to display Form A if the user is logged in and Form B if the user is not logged in.

    Posted 12 years ago on Wednesday November 30, 2011 | Permalink
  3. Is that a (relatively) new option? It seems like I was looking for that a while ago! For now, I've just got the submit button hidden via CSS. For this situation, I've got a plugin I wrote that connects particular forms up to particular capabilities, so the plugin grabs that information to determine which forms get need to be hidden and which ones don't, so I'm going to try to play around with that route and see if I can integrate it better. For now though, it works.

    Posted 12 years ago on Wednesday November 30, 2011 | Permalink
  4. It's new in the 1.6 version of the plugin which was recently released.

    Posted 12 years ago on Thursday December 1, 2011 | Permalink