【发布时间】:2015-01-06 21:42:19
【问题描述】:
我一直在努力解决这个自定义重力表单中的两个选择字段。第一个字段是网络研讨会列表。第二个字段是网络研讨会日期列表。显示哪些日期取决于您选择的网络研讨会。我计划使用 jQuery 对该列表进行排序,但为了做到这一点,我需要在网络研讨会日期选择字段中的选择选项中添加一个属性。目前我想不通如何修改GF的选择选项功能。这是我的自定义函数目前的样子:
//Populate Webinars form field for Webinar dates
add_filter( 'gform_pre_render_2', 'populate_webinar_dates' );
function populate_webinar_dates( $form ) {
foreach( $form[ 'fields' ] as &$field ) {
if( $field[ 'type' ] != 'select' || strpos( $field[ 'cssClass' ], 'populate-dates' ) === false )
continue;
$posts = new WP_Query( 'numberposts=-1&post_status=publish&post_type=vtl_webinar' );
$choices = '<option value=" ">Select a date</option>';
while ( $posts->have_posts() ) : $posts->the_post();
while ( has_sub_field( 'dates_available' ) ) :
$post_dates = array( 'date' => get_sub_field( 'date' ) );
$post_title = array( 'name' => str_replace( " ", "-", get_the_title() ) );
//$choices[] = array( 'text' => $post_dates['date'], 'value' => $post_dates['date'] );
$choices = '<option value="' . $post_dates['date'] . '" data-id="' . $post_title . '">' . $post_dates['date'] . '</option>';
endwhile;
endwhile;
$field[ 'choices' ] = $choices;
}
return $form;
}
显然,这条线是行不通的:
$choices = '<option value="' . $post_dates['date'] . '" data-id="' . $post_title . '">' . $post_dates['date'] . '</option>';
它需要类似于该行上方注释形式的参数,但您不能只将自己的属性添加到该行。您必须根据 GF 正在寻找的现有参数集进行工作。有人可以帮我解决这个问题吗?我只需要在选项中获取数据属性即可。
【问题讨论】:
标签: wordpress forms gravity-forms-plugin