-1

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);
4

1 に答える 1

1
'#attributes' => array(
   'class' => array('service-tax'),
   'amount' => $amt
),
于 2013-07-23T08:19:12.743 に答える