2016-12-23 5 views
2

重力フォームにチェックボックスを動的に追加しましたが、最後の2アイテムを選択して送信をクリックすると、「このフィールドは必須です」というエラーメッセージが表示されます。私は1番目の項目を選択するか2番目、3番目の場合エラーとフォームは正常に送信されません。重力フォームに動的に入力されたチェックボックスエラー

ここに私のPHPコードです。ここで

add_filter('gform_pre_render_56', 'get_menu_options'); 
 
add_filter('gform_pre_validation_56', 'get_menu_options'); 
 
add_filter('gform_pre_submission_filter_56', 'get_menu_options'); 
 

 
function get_menu_options($form){ 
 
/****get all beverages from post*****/ 
 
$beverages = array_filter(get_post_meta(get_the_ID(), 'wpcf-beverages', false)); 
 

 
$form['fields'][22]->choices = set_field_choices($beverages); 
 

 
return $form; 
 

 
} 
 

 
function set_field_choices($values){ 
 
    $field_choices = array(); 
 
    $isSelected = (count($values) == 1)?true:false; 
 
    foreach ($values as $value) { 
 
     $field_choices[] = array(
 
       'text'   => $value, 
 
       'value'   => $value, 
 
       'isSelected' => $isSelected 
 
      ); 
 
    } 
 
    return $field_choices; 
 
}

page link

おかげ

答えて

0

で[OK]を、私はこの問題を考え出しました。我々はまた 'form_field_value_ $パラメータ' フィルタを設定することができます

add_filter('gform_pre_render_56', 'get_menu_options'); 
 
add_filter('gform_pre_validation_56', 'get_menu_options'); 
 
add_filter('gform_pre_submission_filter_56', 'get_menu_options'); 
 
add_filter('gform_admin_pre_render_56', 'get_menu_options'); 
 

 
function get_menu_options($form){ 
 

 
$buffetstations1 = array_filter(get_post_meta(get_the_ID(), 'wpcf-buffet-station-1', false)); 
 

 
foreach ($form[ 'fields' ] as $key => $field) { 
 

 
if($field->id == 72){ 
 
     \t 
 
if(count($buffetstations1) == 0){ 
 
unset ($form['fields'][$key]); 
 
} 
 
    \t $choices = array(); 
 
    \t $inputs = array(); 
 
    \t $field_id = $field->id; 
 
    \t $input_id = 1; 
 

 
foreach ($buffetstations1 as $buffetstation1) { 
 
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs) 
 

 
if ($input_id % 10 == 0) { 
 
    $input_id++; 
 
} 
 

 
$choices[] = array('value' => $buffetstation1, 'text' => $buffetstation1); 
 
$inputs[] = array('label' => $buffetstation1, 'id' => "{$field_id}.{$input_id}"); 
 
$input_id++; 
 
} 
 
$field->choices = $choices; 
 
$field->inputs = $inputs; 
 
\t \t  
 
} 
 

 
} 
 

 
return $form; 
 

 
}

0

入力されたIDに目を維持する必要があります。 '赤'、 '緑'、 '青'、 '黄'、 'オレンジ'、およびallowフィールドに動的に入力されるチェックボックスフィールドがある場合、 'color'は青と緑のチェックボックスをチェックします。

add_filter('gform_field_value_color', 'set_checkbox'); 
function set_checkbox($form) { 
    return 'Blue,Green'; 
} 

これは最近重力に追加されたと思います。

関連する問題