• Resolved DaPunkt

    (@dapunkt)


    Hello,

    Very nice plugin!

    I am playing with the function:

    function filter_field_attributes( $attributes, $field, $form, $args ) {
    $attributes[‘id’] = ‘form-id’;

    return $attributes;
    }

    How can I address a specific field?
    $attributes[‘class’] = ‘button’; isn’t working?

    Can anyone give an example of a broader use of this function?

    thx,

    Steven

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi!

    I’m not quite sure what you’re aiming to achieve. Are you trying to add a class to a field or are you trying to edit the attributes of a specific field?

    Thanks for reaching out!

    Thread Starter DaPunkt

    (@dapunkt)

    actually both, I just want to see a more detailed real life example of the above function, for instance how can I address a specific field:

    $field =’myfield’;

    return $field?

    Plugin Author fabianlindfors

    (@fabianlindfors)

    I see!

    You can adress a specific field by checking the name or key of $form. Something like this:

    
    function filter_field_attributes( $attributes, $field, $form, $args ) {
    // Check field name
    if ( 'field_name' != $field['name'] ) {
      return $attributes;
    }
    
    // Perform changes
    $attributes[‘id’] = ‘form-id’;
    
    return $attributes;
    }
    

    This will only apply to the field with name field_name. You can do similar things if you instead want to address fields based on their field key or type.

    Hope this helps!

    Hi @fabianlindfors

    Thanks for such a wonderful plugin!

    I am also a little confused on how to target specific field inputs and add classes to them. Would you mind going into a little more detail on how that works?

    Kindly-

    • This reply was modified 6 years, 1 month ago by joshwhite.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Style the form’ is closed to new replies.