Drupal7 - 如何在属性/占位符中使用变量?
$form['name'] = array(
'#type' => 'textfield',
//'#maxlength' => 50,
'#size' => 60,
'#required' => TRUE,
'#title' => t('Name'),
'#attributes' => array('placeholder' => 'Max'),
);
上面的例子有效,下面的无效!
...
$name = $account->field_name['und']['0']['value'];
function confirm_personal_user_information() {
$form['name'] = array(
'#type' => 'textfield',
//'#maxlength' => 50,
'#size' => 60,
'#required' => TRUE,
'#title' => t('Name'),
'#attributes' => array('placeholder' => $name),
);
...
}
有任何想法吗?先感谢您!
已编辑:=================================================解决方案:在表单函数中定义变量,但是,验证有问题......
例子:
function confirm_personal_user_information() {
$name = 'Max Power';
$form['#action'] = 'Validate';
$form['#id'] = 'form_user_information_xxx';
//$form['#validate'] = form_user_information_validators();
$form['#submit'] = 'form_user_information_submit';
$form['#prefix'] = '<div id="form_user_information">';
$form['#suffix'] = '</div>';
$form['name'] = array(
'#type' => 'textfield',
//'#maxlength' => 50,
'#size' => 60,
'#required' => TRUE,
'#title' => t('Name'),
//'#attributes' => array('placeholder' => $name),
'#default_value' => "$name",
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Validate');
return $form;
}
//print form
$form = drupal_get_form('confirm_personal_user_information');
print drupal_render($form);