Drupal 7 - Overriding the basic form of HTML markup

I'm really struggling to figure out the Drupal Form API ... actually Drupal as a whole.

Here is my problem, I created a form with rendering, but what I like right now is div wrappers around certain form elements, so I will style my form in a way that suits my site and not some standard shit.

Could someone please help, or at least in the right direction of a “good” textbook, and not some brief and very vague nonsense, plastered all over the Internet?

thank.

+5
source share
2 answers

hook_form_alter is your friend here.

theme.php , ..

, .

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;
  }
}

, , . , , .

, , :

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>';
  }
}
+13

.

  • , field.tpl.php template_preprocess_field().
  • ( , , Drupal ), . , .
+2

All Articles