【发布时间】:2012-03-20 20:09:13
【问题描述】:
我有一个带有一堆字段的 drupal 7 表单:
$form['account_type'] = array(
'#title' => t('Utility Account Type'),
'#type' => 'select',
'#options' => necp_enrollment_administration_portal_account_type_options(),
'#required' => TRUE,
'#default_value' => isset($form_state['values']['account_type']) ? $form_state['values']['account_type'] : '',
);
// Should show if account_type = 1
$form['home_wrapper'] = array(
'#type' => 'fieldset',
'#states' => array(
'visible' => array(
':input[name="account_type"]' => array('value' => 1),
),
),
);
$form['home_wrapper']['first_name_1'] = array(
'#title' => t('Primary Account First Name'),
'#type' => 'textfield',
'#default_value' => isset($form_state['values']['first_name_1']) ? $form_state['values']['first_name_1'] : '',
'#states' => array(
'required' => array(
':input[name="account_type"]' => array('value' => 1),
),
),
);
$form['home_wrapper']['last_name_1'] = array(
'#title' => t('Primary Account Last Name'),
'#type' => 'textfield',
'#default_value' => isset($form_state['values']['last_name_1']) ? $form_state['values']['last_name_1'] : '',
'#states' => array(
'required' => array(
':input[name="account_type"]' => array('value' => 1),
),
),
);
// Should show if account_type = 2
$form['business_wrapper'] = array(
'#type' => 'fieldset',
'#states' => array(
'visible' => array(
':input[name="account_type"]' => array('value' => 2),
),
),
);
$form['business_wrapper']['company_name'] = array(
'#title' => t('Company/Organization'),
'#type' => 'textfield',
'#default_value' => isset($form_state['values']['company_name']) ? $form_state['values']['company_name'] : '',
'#states' => array(
'required' => array(
':input[name="account_type"]' => array('value' => 2),
),
),
);
在 Firefox/Chrome/Opera 所有版本中,此表单的行为都应如此。然而,在所有版本的 IE 中,表单初始化为 display:none;无论 account_type 中的值是什么,所有条件字段的样式都是如此。更改 account_type 的选定选项不会影响隐藏状态。
任何调试此表单的技巧都很棒。
注意事项:
- 我不是一个 Drupal 开发人员,我继承了这个站点。只是想解决最后几个错误,以便我们可以上线
- 字段比上面列出的要多,我只是给了你一些适用的字段,这样你就可以了解我的表单是如何设置的
- 正在开发的表单的当前 URL:https://northeastcleanpower.com/enroll_new
- 我正在使用http://www.browserstack.com/ 来调试 IE 7 - 10pp4(不过我认为我们只需要支持 8 及更高版本)
我也试过了:
':select[name="account_type"]' => array('value' => 1),'#edit-account-type' => array('value' => 1),
【问题讨论】:
标签: php drupal drupal-7 drupal-modules drupal-forms