hook_form_alter là bạn của bạn ở đây.
Trong file template.php của chủ đề của bạn, bạn có thể thêm tiền tố và hậu tố với các hình thức, các yếu tố hình thức, vv
Dưới đây là một ví dụ từ một trang web tôi đã làm thời gian gần đây.
function bhha_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_login') {
$form['#prefix'] = '<div class="loginForm">';
$form['#suffix'] = '</div>';
$form['name']['#title'] = Null; // Change text on form
$form['name']['#description'] = Null; // Change text on form
$form['name']['#attributes'] = array('placeholder' => t('username'));
$form['name']['#size'] = '30';
$form['pass']['#title'] = Null;
$form['pass']['#description'] = Null; // Change text on form
$form['pass']['#attributes'] = array('placeholder' => t('password'));
$form['pass']['#size'] = '30';
//$form['actions']['submit']['#value'] = t('password');
$form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/Login.png');
$form['links']['#markup'] = '<a class="user-password" href="'.url('user/password').'">' . t('Forgot your password?') . '</a>'; // Remove Request New Password from Block form
$form['links']['#weight'] = 540;
}
}
Kiểm tra mã của bạn để lấy biểu mẫu bạn muốn id của chủ đề. Thay thế dấu gạch dưới bằng dấu gạch ngang và bạn sẽ có thể sử dụng ví dụ trên để thực hiện những gì bạn muốn.
Tại đó là cơ bản nhất mà tôi đoán một ví dụ sẽ là:
function THEME_NAME_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'FORM_ID') {
// Adds a wrapper div to the whole form
$form['#prefix'] = '<div class="loginForm">';
$form['#suffix'] = '</div>';
// Adds a wrapper div to the element NAME
$form['name']['#prefix'] = '<div class="formRow">';
$form['name']['#suffix'] = '</div>';
}
}
Bạn đã tạo biểu mẫu tùy chỉnh hoặc bạn muốn tạo kiểu tùy chỉnh? Hãy thử [hướng dẫn] này (http://www.jaypan.com/tutorial/themeing-drupal-7-forms-including-css-and-js) hoặc [this this] (http://www.digett.com)/blog/05/26/2011/how-theme-comment-form-drupal-7) –
Tôi đã tạo biểu mẫu tùy chỉnh của riêng mình bằng cách sử dụng API biểu mẫu nhưng tôi không thể tạo kiểu theo cách tôi muốn vì tôi cần nhóm một tải của yếu tố tức là chi tiết cá nhân (tên, địa chỉ, điện thoại, vv, vv). Về cơ bản, tôi muốn trượt các phần của biểu mẫu trên màn hình, khi mỗi phần được điền, đó là lý do tại sao tôi cần thêm đánh dấu HTML bổ sung. –
cảm ơn câu trả lời. Hướng dẫn đầu tiên được gửi bởi JAYPAN hoạt động tốt sau khi phát hành tôi phải khởi động lại mô-đun sau khi một số thay đổi nhất định. –