我正在使用Drupal 7的Form API构建一个表单...到目前为止,所有这些都是犹太教的;但看起来我撞墙了。寻找正确方向的指导/点:
用户使用CAS(中央身份验证服务)登录。单击表单以创建新记录。
在表单顶部,我有一个复选框(默认选中),后跟三个字段:ID,Name,Phone和Email。
我使用以下代码预先填充这些字段:
<?php
//... other code prior to this function
function user_form_form_start($form, &$form_state) {
global $user;
$result = db_query('select u.name, dn.field_full_name_value, pn.field_phone_value, u.mail from field_data_field_full_name dn join field_data_field_phone pn on (dn.entity_id = pn.entity_id) join users u on (pn.entity_id = u.uid) where u.uid = :uid', array(':uid' => $user->uid))->fetchAll();
$myID = isset($result[0]->name) ? $result[0]->name : "";
$myFullName = isset($result[0]->field_full_name_value) ? $result[0]->field_full_name_value : "";
$myPhoneNumber = isset($result[0]->field_phone_value) ? substr($result[0]->field_phone_value, 2) : "";
$myEmailAddress = isset($result[0]->mail) ? $result[0]->mail : "";
$form['tab_user'] = array(
'#type' => 'fieldset',
'#title' => t('User Details'),
'#collapsible' => TRUE, // Added
'#collapsed' => FALSE, // Added
);
$form['tab_user']['user_sameAsAuthor'] = array(
'#type' => 'checkbox',
'#title' => t('Filling it out for myself'),
'#default_value' => isset($form_state['object']->user_sameAsAuthor) ? $form_state['object']->user_sameAsAuthor : TRUE,
// '#required' => TRUE,
);
$form['tab_user'] ['user_id'] = array(
'#type' => 'textfield',
'#title' => t('My CAS ID'),
'#default_value' => isset($form_state['object']->user_id) ? $form_state['object']->user_id : $myID,
// '#required' => TRUE,
);
$form['tab_user']['user_name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => isset($form_state['object']->user_name) ? $form_state['object']->user_name : $myFullName,
// '#required' => TRUE,
);
$form['tab_user']['user_phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone Number'),
'#default_value' => isset($form_state['object']->user_phone) ? $form_state['object']->user_phone : $myPhoneNumber,
'#attributes' => array('class' => array('phoneNumberField')),
'#size' => 20,
// '#required' => TRUE,
);
$form['tab_user']['user_email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#default_value' => isset($form_state['object']->user_email) ? $form_state['object']->user_email : $myEmailAddress,
// '#required' => TRUE,
);
return $form;
}
//... other code after this function
?>
上述所有作品都很精彩!这就是我陷入困境的地方:
如果用户取消选中该复选框,我希望用户输入新ID。基于任何ID用户输入,我如何“ajaxically”获取名称,电话和电子邮件进行LDAP查找?
非常感谢任何和所有帮助!
编辑:
道歉!忘记在我的研究中提到,我挖掘了Form API(当然)并注意到textfield
(https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7.x#textfield)接受ajax
属性(https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7.x#ajax)。但是,示例代码不会完全回答我的问题。