Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:12:06+00:00 2026-06-06T22:12:06+00:00

I’m really struggling to get my head around Drupal Form API…actually Drupal as a

  • 0

I’m really struggling to get my head around Drupal Form API…actually Drupal as a whole.

Here’s my problem, I’ve created a form with renders fine, however what I’ve like to do now is wrapper divs around certain form elements, this is so I style my form in a way that’ll suit my site and not some box standard crap.

Can someone please help or at the least point in the right direction of a “good” tutorial and not some brief and very vague nonsense that is plastered all over the web?

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:12:07+00:00Added an answer on June 6, 2026 at 10:12 pm

    hook_form_alter is your friend here.

    In your theme’s template.php file you can add prefixes and suffixes to forms, form elements etc.

    Below is an example from a site I did recently.

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

    Inspect your code to get the form you want to theme’s id. Replace underscores with hyphens and you should be able to use the example above to do what you want.

    At it’s most basic I guess an example would be:

    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>';
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.