Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • Login
  • Get Formidable Forms

frm_field_type

Last Updated: May 9, 2018

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Field Options and Values → frm_field_type
Heads up!
This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Use this hook to hide fields depending on certain conditions.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

Usage

add_filter('frm_field_type', 'change_my_field_type', 10, 2);
function change_my_field_type($type, $field)

Parameters

  • $type (string)
  • $field (object)

Examples

Hide a field from non-editors

Use this code to hide fields from all user types except editors. The field will still be visible in the admin area.

add_filter('frm_field_type', 'change_my_field_type', 10, 2);
function change_my_field_type($type, $field){
  if(in_array($field->id, array(125,126,127))){ //change 125, 126, and 127 to the ids of fields to hide
   if(!is_admin() and !current_user_can('editor'))//if current user is not an editor
$type = 'hidden'; //hide the fields
  }
  return $type;
}

Hide a field when editing

Use this code to hide certain fields when users are editing forms. The fields will still be visible in the admin area when editing entries.

add_filter('frm_field_type', 'change_my_field_type', 10, 2);
function change_my_field_type($type, $field){
 if(in_array($field->id, array(125, 126))){ //change 125 and 126 to the ids of the fields to hide
      global $frm_vars;
      if((!is_admin() || defined('DOING_AJAX')) && isset($frm_vars['editing_entry']) && $frm_vars['editing_entry']) { 
        //if not in admin area and editing an entry
        $type = 'hidden'; //hide this field
      }
  }
  return $type;
}

Hide a field when not editing

Use this code to hide certain fields when users are creating an entry (show field(s) only when editing). The fields will still be visible in the admin area when creating entries.

add_filter('frm_field_type', 'change_my_field_type', 10, 2);
function change_my_field_type($type, $field){
 if(in_array($field->id, array(125, 126))){ //change 125 and 126 to the ids of the fields to hide
      global $frm_vars;
      if((!is_admin() || defined('DOING_AJAX')) && (!isset($frm_vars['editing_entry']) || !$frm_vars['editing_entry'])) {
        //if not in admin area and not editing an entry
        $type = 'hidden'; //hide this field
      }
  }
  return $type;
}

Hide a field depending on a value in another

add_filter('frm_field_type', 'change_my_field_type', 10, 3);
function change_my_field_type($type, $field, $value){
  if($field->id == 25){ //change 25 to the id of the field to conditionally hide
    global $my_required_id, $user_ID; 
    if($my_required_id == $user_ID) //if current user is not an editor
      $type = 'hidden'; //hide this field
  }else if($field->id == 21){ //change 21 to the id of the field to depend on
     global $my_required_id; 
     $my_required_id = $value; //save the required value to reference when we hit the other field
  }
  return $type;
}

Hide fields from certain users when editing entries

Use this code to hide fields from specified user when editing entries. The field will still be visible in the admin area.

add_filter('frm_field_type', 'change_my_field_type', 10, 2);
function change_my_field_type($type, $field){
 if(in_array($field->id, array(15981, 15980))){ //change 15981 and 15980 to the ids of the fields to hide
     $user = wp_get_current_user();
	 $uid = $user->ID;
	 $people = array(34, 72, 82);  //Change 34,72,82 to the ID of the users you want to hide these fields from
      global $frm_vars;
      if((!is_admin() || defined('DOING_AJAX')) && isset($frm_vars['editing_entry']) && $frm_vars['editing_entry']) { 
        //if not in admin area and editing an entry
		
		if(in_array($uid, $people)){
        $type = 'hidden'; //hide this field
		}
      }
  }
  return $type;
}
  • Usage
  • Parameters
  • Examples
    • Hide a field from non-editors
    • Hide a field when editing
    • Hide a field when not editing
    • Hide a field depending on a value in another
    • Hide fields from certain users when editing entries
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form. Maybe you need to log in?

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 Strategy11, LLC. Formidable FormsĀ® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started See User Reviews