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.

Turn off 'required' fields if user is Wordpress admin ??

  1. Deepend
    Member

    Hi, I am trying to make a form that has required fields, but if user is a logged-in wordpress admin, the required fields don't need to be filled in... I thought something like this would do it:

    add_filter('gform_validation_2', 'admin_override', 10, 4);
    function admin_override($result, $value, $form, $field){
    	if ( current_user_can('manage_options') )
         {
            $result["is_valid"] = true;
         } else {
            $result["is_valid"] = false;
         };
    	return $result;
    }

    But it doesn't work, in fact it stops the form from loading all together... Can anyone please help me work this out?

    Posted 11 years ago on Thursday November 29, 2012 | Permalink
  2. There is more to gform_validation thatn you are showing here. Is that all your code? Please see the documentation here: http://www.gravityhelp.com/forums/topic/extract-file-upload-name-in-email-notification#post-69404

    Instead of pretending the fields are valid when logged in as an admin, no matter what was submitted, how about using the gform_pre_render filter and applying it only when the user is a logged in admin?

    http://www.gravityhelp.com/documentation/page/Gform_pre_render

    You have access to the $form object, and each field in the form has an 'isRequired' item in the array:

    // loop through all the fields
    $form['fields'][0]['isRequired'] = 0; /* or possibly '' */

    You could set them all to 0 or clear them out if the logged in member is an admin.

    Posted 11 years ago on Thursday November 29, 2012 | Permalink