I know i can customize the markup for a gravity form field using their gform_field_input filter. Is there a a

add_filter( 'gform_field_input', 'my_gf_inputs', 10, 5 );
function my_gf_inputs( $input, $field, $value, $lead_id, $form_id ) {
    if ($field->formId == 1){ //the form i'm customizing

        switch( $field->id ){
            case 1: //email field in that form
            $input = <<<INPUT
<div class="col-sm-3 col-md-4">
    <div class="form-group">
        <input name="input_1" id="input_1_1" type="text" value="" placeholder="name" class="form-control" tabindex="1" aria-invalid="false">

Is there a way i can produce different markup for the same form? That is, suppose it appears in both the header and the footer of a page but in a different design. Is there a way i can use the shortcode to indicate that? for example by adding an arbitrary key/value parameter like say, "position", like this?

[gravityform id="1" title="false" description="false" position="header"]

[gravityform id="1" title="false" description="false" position="footer"]

and then use positions value in the filter for different markup?


You have three ways:

1) To find out the correct hook (at this moment i can tell if it even exists for that)

2) To use only CSS (For example, just target your first form with #header .form-group{} ( or by its another parent div, instead of #header )

3) Use the GLOBAL variable to count each time whenever that function executes. i.e, see example:

add_filter( ........... );
function ..........{
    $GLOBALS['my_form_counter'] = empty($GLOBALS['my_form_counter']) ? 1 : $GLOBALS['my_form_counter'] + 1;
    if($GLOBALS['my_form_counter'] == 1){
       //it's the first time of the form EXECUTION, so you know where it is happening.. Code what you want

    if($GLOBALS['my_form_counter'] == 2){
       //it's the second time of the form EXECUTION, so do now what you want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.