最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Gravity Forms Button Text

programmeradmin2浏览0评论

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:

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

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

Share Improve this question asked Mar 26, 2020 at 17:07 joshmrodgjoshmrodg 1,1731 gold badge16 silver badges42 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/form-object/#advanced-properties You may need to confirm the key is text and not something else. Hope this helps.

发布评论

评论列表(0)

  1. 暂无评论