要在数组中以数组元素为目标


Want to target array element in an array

我想要的目标是在时隙数组中的数组元素。这是代码

function example_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
    $active = array(10 => t('10 - 11 am'), 11 => t('11 - 12 pm'), 12 => t('12 - 1 pm'), 13 => t('1 - 2 pm'), 14 => t('2 - 3 pm'),15 => t('3 - 4 pm'), 16 => t('4 - 5 pm'), 17 => t('5 - 6 pm'), 18 => t('6 - 7 pm'), 19 => t('7 - 8 pm'), 20 => t('8 - 9 pm'), 21 => t('9 - 10 pm'));
    $default_date=date("y-m-d"); $current_time = date('H');
    if($current_time <= 19) {
        $myvalues = example_pane_value($default_date);
        $default_time = $myvalues[0]; $time_slot_title=$myvalues[1]; $current_orders = $myvalues[2];
        //print "time".$default_time." date".$time_slot_title;
        $form['time_slot'] = array(
            '#type' => 'radios',
            '#title' => $time_slot_title,
            '#default_value' => $default_time,
            '#options' => $active,
        );
        if (variable_get('blocker_enable_1', 0)) {
            $form['time_slot'][$active][11] = array( '#disabled' => TRUE,);
        }
    } 
} 

如何我将目标的活动数组的项目命名为11,并使其禁用,因为它是一个单选按钮在一个单选组。谁能解释一下?

对于drupal,我认为禁用它的唯一方法是使用JavaScript并在form_validate中执行检查。

你需要在表单中做这样的事情:

drupal_add_js(
    "$(#RadiosId input[value='ValueToDisable']).prop('disabled', true);",
    "inline"
);

和form validate:

example_pane_checkout_form_validate($form, &$form_sublit){
    if ($form_state['values']['time_slot'] == $ValueToDisable ){
        form_set_error('time_slot', t('NO HACKING PLS!');
    }
}