Gravity form wordpress plugin providing number of useful hooks to easily customize the form. I recently created gravity form add-on wordpress plugin. There I had situation to add custom attribute to the form field. I feel it’s useful share here, so it will be useful for someone.
Gravity form action hook gform_field_content is pretty useful to do our job. Let’s see how to do that!
add_filter( 'gform_field_content', 'add_custom_attr', 10); function add_custom_attr($field_content, $field, $value, $lead_id, $form_id){ if($field->type == 'xxx'){ $field_content = str_replace( 'type=', "data-custom_attr='yyyy' type=", $field_content ); } return $content; }