• Resolved gvanto

    (@gvanto)


    with NF 2.9, we used to omit a field completely from a form with (for example we don’t want to show Name + Email at all if user is logged in):

    add_filter('ninja_forms_display_fields_array', 'dpcontent_filter_ninja_form_fields', 10, 2);
    
    function dpcontent_filter_ninja_form_fields($field_results, $form_id) { 
       unset($field_results[$x]); // where x is name / email

    So I now try and do this with NF3 (but line below breaks form – it does not even appear at all):

    add_filter('ninja_forms_display_fields', 'dpcontent_nf_display_fields', 10, 1);
    
    function dpcontent_nf_display_fields($fields) {    
        unset($fields[2]); // this line breaks the form, commenting it fixes form but how to remove field from form?
        
        return $fields;
    }
    • This topic was modified 8 years, 2 months ago by gvanto.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Kyle B. Johnson

    (@kbjohnson90)

    @gvanto check the format of the passed $fields parameter, as it may have changed.

    Plugin Contributor Kyle B. Johnson

    (@kbjohnson90)

    Also, we can better assist with development questions at https://developer.ninjaforms.com/slack

    • This reply was modified 8 years, 2 months ago by Kyle B. Johnson. Reason: Update URL to be clickable
    Thread Starter gvanto

    (@gvanto)

    hey @bkjohnson90,

    I’ve looked at the structure of the $fields parameter, (debug output below), it’s fairly straightforward.
    unset-ing an array element (each element corresponding to a field object) used to work (in NF 2.9.7) – field would simply not appear (which is desired behavior).

    In NF3 it breaks entire form (form not appearing at all).

    Will message you on slack, thanks.

    DBG: $fields=
    
    array (size=5)
      0 => 
        array (size=28)
          'type' => string 'listselect' (length=10)
          'order' => float 0
          'fav_id' => float 0
          'def_id' => float 0
          'label' => string 'Department' (length=10)
          'input_limit_msg' => string 'character(s) left' (length=17)
          'label_pos' => string 'above' (length=5)
          'list_type' => string 'dropdown' (length=8)
          'multi_size' => float 5
          'list_show_value' => float 1
          'calc_auto_include' => float 0
          'user_state' => float 0
          'num_sort' => float 0
          'show_help' => float 0
          'show_desc' => float 0
          'desc_pos' => string 'none' (length=4)
          'required' => float 0
          'options' => 
            array (size=11)
              0 => 
                array (size=6)
                  ...
              1 => 
                array (size=6)
                  ...
              2 => 
                array (size=6)
                  ...
              3 => 
                array (size=6)
                  ...
              4 => 
                array (size=6)
                  ...
              5 => 
                array (size=6)
                  ...
              6 => 
                array (size=6)
                  ...
              7 => 
                array (size=6)
                  ...
              8 => 
                array (size=6)
                  ...
              9 => 
                array (size=6)
                  ...
              10 => 
                array (size=6)
                  ...
          'key' => string 'listselect_187' (length=14)
          'objectType' => string 'Field' (length=5)
          'objectDomain' => string 'fields' (length=6)
          'id' => float 22
          'beforeField' => string '' (length=0)
          'afterField' => string '' (length=0)
          'parentType' => string 'list' (length=4)
          'element_templates' => 
            array (size=2)
              0 => string 'listselect' (length=10)
              1 => string 'input' (length=5)
          'old_classname' => string 'list-select' (length=11)
          'wrap_template' => string 'wrap' (length=4)
      1 => 
        array (size=30)
          'type' => string 'textarea' (length=8)
          'order' => float 1
          'fav_id' => float 0
          'def_id' => float 0
          'label' => string 'Enquiry' (length=7)
          'input_limit_msg' => string 'character(s) left' (length=17)
          'label_pos' => string 'above' (length=5)
          'textarea_rte' => float 0
          'textarea_media' => float 0
          'disable_rte_mobile' => float 0
          'input_limit_type' => string 'char' (length=4)
          'calc_auto_include' => float 0
          'num_sort' => float 0
          'show_help' => float 0
          'show_desc' => float 0
          'desc_pos' => string 'none' (length=4)
          'element_class' => string 'contact-us-enquiry' (length=18)
          'required' => float 1
          'key' => string 'enquiry' (length=7)
          'objectType' => string 'Field' (length=5)
          'objectDomain' => string 'fields' (length=6)
          'manual_key' => boolean true
          'admin_label' => string 'enquiry' (length=7)
          'id' => float 23
          'beforeField' => string '' (length=0)
          'afterField' => string '' (length=0)
          'parentType' => string 'textarea' (length=8)
          'element_templates' => 
            array (size=2)
              0 => string 'textarea' (length=8)
              1 => string 'input' (length=5)
          'old_classname' => string '' (length=0)
          'wrap_template' => string 'wrap' (length=4)
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to omit fields programmatically in NF3?’ is closed to new replies.