首页 > 解决方案 > 重力表单在提交时动态填充单选按钮为空

问题描述

我想从 wordpress 术语中动态添加单选按钮,但我想将其保存到数据库中。如果需要,则检查将是错误的。可以帮助理解为什么重力形式的示例不适用于单选按钮吗?

这是我的代码:

add_filter('gform_pre_render_1', 'populate_cat_members');
add_filter('gform_pre_validation_1', 'populate_cat_members' );
add_filter('gform_pre_submission_filter_1', 'populate_cat_members' );
add_filter('gform_admin_pre_render_1', 'populate_cat_members');

function populate_cat_members($form)
{
 foreach ($form['fields'] as $field) {

 if ($field['id'] == 32) {
  $terms = get_terms('cat_members', array('hide_empty' => false, 'oderby' => 'name'));
  $choices = array();
  $numItems = count($terms);
  foreach ($terms as $post) {
    $choices[] = array('text' => $post->name, 'value' => $post->term_id);
  }
  $field->choices = $choices;
 }
}
 return $form;
}

谁能帮帮我,为什么我不能保存数据?

标签: wordpresspopulatetaxonomy-termsgravityforms

解决方案


推荐阅读