Formidable Forms

The Most Advanced WordPress Forms Plugin and Form Builder

  • Features
  • Pricing
  • Blog
  • Support
  • 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;
}
  • 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
Categories
×

Categories

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

Using WordPress and want to get Formidable Forms for free?

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

Top Features

  • Front End Editor
  • Repeating Fields
  • Views from Entries
  • Calculator Forms
  • Conditional Logic
  • Visual Form Styler
  • Form Templates
  • User Submitted Posts
  • File Upload Forms
  • Spam Protection
  • Multi Page Forms
  • Surveys & Polls
  • Form Graphs & Charts
  • Save and Continue
  • Mobile Forms
  • Stripe Forms
  • PayPal Forms
  • WooCommerce Forms
  • MailChimp Forms
  • User Registration
  • Signature Forms
  • Bootstrap Forms
  • Quiz Maker
  • Zapier Forms
  • Salesforce Forms
  • HubSpot Forms
  • API Webhooks
  • Multilingual Forms
  • Directories

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • Blog

Copyright © 2021 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