首页 > 解决方案 > 重力表单/WordPress 填充来自 ACF 字段的单选按钮选项

问题描述

我正在尝试从 ACF 字段中填充单选按钮中的选项。我想出了下面的解决方案,基本上只是字符串替换。但是,此解决方案仅在视觉前端有效。例如,当收到管理员通知时,它仍然返回原始文本“Valg 1:, Valg 2: or valg3”。

我怎样才能使代码在管理员通知等中工作?

我一直在寻找各种重力形式过滤器,但由于某种原因无法使其工作:

gform_pre_render
gform_pre_validation
gform_pre_submission_filter
gform_admin_pre_render

我的代码:

add_filter( 'gform_field_choice_markup_pre_render_16_11', function ( $choice_markup, $choice, $field, $value ) {
    if ( $field->get_input_type() == 'radio' ) :

            if( get_field('valg_checkbox') == 'Valg1' ) {
 switch ( rgar( $choice, 'text' ) ) {
  case "Valg 1:":
                $description = get_field('valg_1');
                $current = "Valg 1";
                break;
}
} elseif ( get_field('valg_checkbox') == 'Valg2' ) {
switch ( rgar( $choice, 'text' ) ) {
  case "Valg 1:":
                $description = get_field('valg_1');
                $current = "Valg 1";
                break;
            case "Valg 2:":
                $description = get_field('valg_2');
                $current = "Valg 2";
                break;
} } else {
switch ( rgar( $choice, 'text' ) ) {
  case "Valg 1:":
                $description = get_field('valg_1');
                $current = "Valg 1";
                break;
            case "Valg 2:":
                $description = get_field('valg_2');
                $current = "Valg 2";
                break;
            case "Valg 3:":
                $description = get_field('valg_3');
                $current = "Valg 3";
                break;
} 
            }

    endif;

    return str_replace( ">".$current, ">".$description, $choice_markup);

}, 10, 4 );

标签: phpwordpressfiltergravity-forms-plugin

解决方案


推荐阅读