Skip to content

Instantly share code, notes, and snippets.

@bhays
Last active October 19, 2023 06:29
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bhays/6885ba3ec9d471bd27bfdf0aede815a6 to your computer and use it in GitHub Desktop.
Add inputName as class to hidden fields and inputs for Gravityforms
add_filter( 'gform_field_css_class', 'hidden_field_css_class', 10, 3 );
function hidden_field_css_class( $classes, $field, $form ) {
if( $field->type == 'hidden' ){
$classes .= ' '.$field->inputName;
}
return $classes;
}
// Add inputName as class to hidden fields
add_filter( 'gform_field_input', 'hidden_field_input', 10, 5 );
function hidden_field_input( $input, $field, $value, $lead_id, $form_id ){
if( $field->type == 'hidden' ){
$input = '<input name="input_'.$field->id.'" id="input_'.$form_id.'_'.$field->id.'" type="hidden" class="gform_hidden '.$field->inputName.'" aria-invalid="false" value="">';
}
return $input;
}
@Garth619
Copy link

very nice ty

@rahulpragma
Copy link

Please try $field->label instead of $field->inputName if the above code doesn't work.
In the recent version of Gravity Forms, I couldn't find a Field Name but a Field Label for hidden fields while creating a form.
Thanks for the direction though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment