重力形式:单选按钮标签的 ACF 字段
Gravity forms: ACF fields for radio button labels
我正在尝试创建在 ACF 文本字段中输入标签的重力表单单选按钮。
我试过使用重力形式 ACF live merge tag。但是,当使用合并标签时,输出结果如下:
<label for="choice_16_11_0" id="label_16_11_0">{custom_field:valg_1}</label>
合并标签只是用纯文本编写的,而不是 ACF 字段中的实际文本。因此我想我必须使用 gform_field_choice_markup_pre_render filter 才能覆盖标签。我遵循了 Gravity forms 文档中的示例。我的代码:
add_filter( 'gform_field_choice_markup_pre_render_16_11', function ( $choice_markup, $choice, $field, $value ) {
if ( $field->get_input_type() == 'radio' ) :
switch ( rgar( $choice, 'text' ) ) {
case "Valg 1":
$description = get_field('valg_1');
break;
case "Valg 2":
$description = get_field('valg_2');
break;
case "Valg 3":
$description = get_field('valg_3');
break;
}
endif;
return str_replace( "</label>", "</label>$description", $choice_markup );
}, 10, 4 );
16 是我的表单 ID,11 是我的单选按钮的字段 ID。但是,我的代码似乎没有做任何事情。关于我可能遗漏的任何指示??
尝试从 return.
中的引号中取出 $description
仅供参考,如果您要替换整个选项,我会替换当前的文本值(否则您的代码只会向现有标签添加后缀)。
if ( $field->get_input_type() == 'radio' ) :
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);
我正在尝试创建在 ACF 文本字段中输入标签的重力表单单选按钮。
我试过使用重力形式 ACF live merge tag。但是,当使用合并标签时,输出结果如下:
<label for="choice_16_11_0" id="label_16_11_0">{custom_field:valg_1}</label>
合并标签只是用纯文本编写的,而不是 ACF 字段中的实际文本。因此我想我必须使用 gform_field_choice_markup_pre_render filter 才能覆盖标签。我遵循了 Gravity forms 文档中的示例。我的代码:
add_filter( 'gform_field_choice_markup_pre_render_16_11', function ( $choice_markup, $choice, $field, $value ) {
if ( $field->get_input_type() == 'radio' ) :
switch ( rgar( $choice, 'text' ) ) {
case "Valg 1":
$description = get_field('valg_1');
break;
case "Valg 2":
$description = get_field('valg_2');
break;
case "Valg 3":
$description = get_field('valg_3');
break;
}
endif;
return str_replace( "</label>", "</label>$description", $choice_markup );
}, 10, 4 );
16 是我的表单 ID,11 是我的单选按钮的字段 ID。但是,我的代码似乎没有做任何事情。关于我可能遗漏的任何指示??
尝试从 return.
中的引号中取出 $description仅供参考,如果您要替换整个选项,我会替换当前的文本值(否则您的代码只会向现有标签添加后缀)。
if ( $field->get_input_type() == 'radio' ) :
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);