【发布时间】:2017-04-06 09:24:25
【问题描述】:
我正在使用选项页面中的 ACF 字段来填充重力形式下拉菜单。这些值是从字段中提取的,但显示在表单顶部(预览中),而不是下拉列表中。我确定这是我如何构建表单的问题。提前感谢您的帮助!
//gravity forms dynamically populate from ACF
add_filter( 'gform_pre_render_1', 'populate_posts' );
add_filter( 'gform_pre_validation_1', 'populate_posts' );
add_filter( 'gform_pre_submission_filter_1', 'populate_posts' );
add_filter( 'gform_admin_pre_render_1', 'populate_posts' );
function populate_posts( $form ) {
global $choices;
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-posts' ) === false ) {
continue;
}
if( have_rows('core_values', 'option') ):
while( have_rows('core_values', 'option') ): the_row();
$choices[] = array( 'text' => the_sub_field('value_mstr_name'), 'value' => the_sub_field('value_mstr_name') );
endwhile;
// update 'Select a Post' to whatever you'd like the instructive option to be
$field->placeholder = 'Select a Post';
$field->choices = $choices;
endif;
}
return $form;
}
【问题讨论】:
标签: php advanced-custom-fields gravity-forms-plugin