1

I am creating several Gravity Forms that use a button instead of an input to submit. I got the button working, but I was wondering how I can use the button text in the admin panel, instead of hard-coding the value?

Screenshot: https://ibb.co/4MtGMmZ

Here is my button code:

add_filter( 'gform_submit_button', 'form_submit_button', 10, 2 );
function form_submit_button( $button, $form ) {
    return "<button class='submit-button' id='gform_submit_button_{$form['id']}'><span><i class='far fa-envelope'></i>Submit</span></button>";
}

Obviously, you can see the hard-coded Submit text

I tried:

add_filter( 'gform_submit_button', 'form_submit_button', 10, 2 );
function form_submit_button( $button, $form ) {
    return "<button class='submit-button' id='gform_submit_button_{$form['id']}'><span><i class='far fa-envelope'></i>".$button."</span></button>";
}

Which puts the input in my button :-( instead of just return the button value

I thought about two possibilities...either pulling that variable from the admin panel page (in the form settings) or if it was possible to have different button code, based on the form, that would work too. Not my favorite option, because the user would not have any control over the value - but I don't even know if that's an option either.

Any help is appreciated!

Thanks,
Josh

1 Answer 1

1

Looks like you can get the buttons text from something like:

add_filter( 'gform_submit_button', 'form_submit_button', 10, 2 );
function form_submit_button( $button, $form ) {
    return "<button class='submit-button' id='gform_submit_button_{$form['id']}'><span><i class='far fa-envelope'></i>".$form['button']['text']."</span></button>";
}

Found here: https://docs.gravityforms.com/form-object/#advanced-properties You may need to confirm the key is text and not something else. Hope this helps.

2
  • you rock! This worked like a champ!! Thanks for the help! Mar 27, 2020 at 3:15
  • Awesome, glad that worked for you!
    – mikerojas
    Mar 27, 2020 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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