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.

Disabling Form Elements

  1. UWEX
    Member

    In our WP environment, we don't want to allow users to create forms that either:
    a) Create Posts, or
    b) Upload files from the general public

    I'd love to be able to allow us Site Administrators to remove these - even if it's with our own plugin rather than an administrative screen - without having to modify your code of course. I couldn't really find a way to do this, however, other than using jQuery to traverse the DOM and hide the elements.

    Any suggestions or thoughts? Thanks!

    Posted 14 years ago on Wednesday July 14, 2010 | Permalink
  2. There's no easy way to do this right now. We may add some hooks in later that will make it easier, but for now, the jQuery path seems like the way to go.

    Posted 14 years ago on Wednesday July 14, 2010 | Permalink
  3. UWEX
    Member

    Heya - just wondering if there was any progress here.

    We'd really like to resist hacking up GravityForms of course, and it seems with a few lines of code inserted into GravityForms would add this functionality for all your users.

    With MultiSite being included in 3.0 now, these features seem really helpful for people running networks. We can't be the only ones who want to deny file uploads or post creation forms, are we??

    I might even be fine with "short-term" more simplistic approach of giving IDs to the form elements so that it's much easier to hide them ourselves.

    Thanks again!

    Posted 14 years ago on Monday November 8, 2010 | Permalink
  4. You can use the "gform_add_field_buttons" to remove the file upload button and the Post Fields group. I think this is all you need to meet your needs.
    Try the following code snippet.

    add_filter("gform_add_field_buttons", "remove_fields");
    function remove_fields($field_groups){
    
        $index = 0;
        $post_field_index = -1;
        $advanced_field_index = -1;
    
        //Finding group indexes
        foreach($field_groups as $group){
            if($group["name"] == "post_fields")
                $post_field_index = $index;
            else if($group["name"] == "advanced_fields")
                $advanced_field_index = $index;
    
            $index ++;
        }
    
        //removing file upload field
        if($advanced_field_index >=0){
            $file_upload_index = -1;
            $index = 0;
            foreach($field_groups[$advanced_field_index]["fields"] as $advanced_field){
    
                if($advanced_field["value"] == "File Upload")
                    $file_upload_index = $index;
                $index++;
            }
    
            unset($field_groups[$advanced_field_index]["fields"][$file_upload_index]);
        }
    
        //removing post field group
        if($post_field_index >= 0)
            unset($field_groups[$post_field_index]);
    
        return $field_groups;
    }
    Posted 14 years ago on Monday November 8, 2010 | Permalink
  5. UWEX
    Member

    This works perfectly - thanks much!! I'll go tweet about awesome support :P

    Posted 14 years ago on Wednesday November 10, 2010 | Permalink