単一のフォーム要素を変更しようとすると、私のコードが動作しています。
チェックボックス(複数の要素)に変更するには何が必要ですか。
私のコードは:
function custom_filter_form_alter(&$form, $form_state, $form_id)
{
if (isset($form['#parameters'][1]['view'])) {
$view = $form['#parameters'][1]['view'];
}
switch ($form_id) {
case 'views_exposed_form':
if ($view->name == 'uc_products') {
custom_filter_range_to_select('sell_price', array(
'0,50' => 'Under $50',
'50,100' => '$50-$100',
'100,150' => '$100-$150',
'150,200' => '$150-$200',
'200,1000' => 'Over $150',
), $form, $form_state);
}
break;
}
}
function custom_filter_range_to_select($field, $value, &$form, &$form_state, $optional = TRUE)
{
$form[$field]['#type'] = 'checkboxes';
if ($optional) {
$value = array_merge(array('All' => 'Any Price'), $value);
}
$form[$field]['#options'] = $value;
unset($form[$field]['min']);
unset($form[$field]['max']);
$f = (array)$form_state['input'][$field];
$array1 = array_pop($f);
$array1 = array_pop($f);
$f ? $form[$field]['#value'] = $f : true;
$form[$field]['#element_validate'] = array('custom_filter_range_validate');
}
function custom_filter_range_validate($element, &$form_state)
{
$array = (array)$element['#post'][$element['#name']];
$array1 = array_pop($array);
$array1 = array_pop($array);
foreach ($array as $key => $value) {
if ($value == 'All') {
$min = $max = '';
}
else {
list($min, $max) = explode(',', $value);
}
$form_state['input'][$element['#name']] = array(
'min' => $min,
'max' => $max,
);
$form_state['values'][$element['#name']] = array(
'min' => $min,
'max' => $max,
);
}
}
ベストアンサー
申し訳ありませんが、適切な答えはありません