Customize login form in drupal 7

Dear experts,

I am trying to add some text to the ajax login register form I installed on my site. I´ve been reading that I have to create my own custom module and use the  hook_form_FORM_id_alter() function, but honestly I don´t know how to implement it to the ajax login register block...

Could you please guide to to the best approach?

thanks in advance,

Winter
glepizaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

glepizaAuthor Commented:
ok, I found this function and it seems to be working, but the message appears as an status message:

function adaptivetheme_subtheme_form_user_login_alter(&$form, &$form_state, $form_id) {
  drupal_set_message('hi');
}


does someone knows how can I add actual text to the footer of that form?

Thanks
0
HagayMandelCommented:
If I understand correctly, your'e using the ajax Login Register module
hook_form_alter will do the trick.
First, you need to know the form's ID:
In the case of the Login form, it is 'user-login-form' (you can check the page's source code).
So the function will look something like this:

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'user-login-form') {
    //Add the required field(s).
  }
}

Open in new window

Now for the component to add to the form, you'll need the form API.
0
glepizaAuthor Commented:
Thank ou very much  Hagay, one question please, do I have to add that code to template.php or I need to create a custom module to add it?

Thanks in advance,
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

HagayMandelCommented:
You can use both:
In a module the function will be module_name_form_alter, and in a theme (template.php), it will be theme_name_form_alter.
If you use it in a theme, make sure to clear caches before expecting to see the change,
0
glepizaAuthor Commented:
Hi there :)

There is something I still don´t know how to do. I was looking at the Form API but it seems that it only helps me to add or edit form controls. But what I really need is to add static text to the form, something like welcome to our site, and a footer.

I think I missed something from the link you sent me, but I still can´t see how can I add just static text.

Could you please help in how to do it?

Thanks,

Winter
0
HagayMandelCommented:
You need to explore Drupal's form API  
This will only give you a start:
/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'user-login-form') {
    //Add the required field(s).
    $form['welcome'] = array (
      '#type' => 'markup', 
      '#id' => 'welcome_message', 
      '#markup' => '<div id ="welcome_div" class ="">Welcome to our site</div>',	
    );
    $form['footer'] = array (
      '#type' => 'markup', 
      '#id' => 'footer_message', 
      '#markup' => '<div id ="footere_div" class ="">This is the footer</div>',	
    );
  }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
glepizaAuthor Commented:
Thank you very much, that is what I need it, now I can do the rest.
Just one thing to confirm. it seems I am not writing the correct form id.
Attached goes and screenshot form the source code, I am writting user-login as the form id, but for some reason it is not taking it.

If i remove the if statement: if($form_id == 'user-login') { the code actually works, so it seems I am not grabbing the correct id :(
Captura-de-pantalla-2013-09-24-a.png
0
HagayMandelCommented:
In my code sample, the form_id  is user-login-form.
In your case it should be: user-login.
The if statement is essential, otherwise ALL FORMS will be altered!
0
glepizaAuthor Commented:
weird, I don´t understand... I am using user-login on my template.php file, but I can´t see the change if I use the if statement, this is what I have so far:

function adaptivetheme_subtheme_form_alter(&$form, $form_state, $form_id) {
        if($form_id == 'user-login') {
          //Add the required field(s).
             $form['name']['#prefix'] =  
            '<b>Welcome to our community </b>';
            
          $form['welcome'] = array (
            '#type' => 'markup',
            '#id' => 'welcome_message',
            '#markup' => '<div id ="welcome_div" class ="">Welcome to our site</div>',      
          );
          $form['footer'] = array (
            '#type' => 'markup',
            '#id' => 'footer_message',
            '#markup' => '<div id ="footere_div" class ="">This is the footer</div>',      
          );
         }
      }
0
glepizaAuthor Commented:
ok, I found what happened. For some reason I still don´t know, the correct form id has an underscore, so it is user_login, instead of user-login.

I saw that on the same link you sent me from the form api :)

thank you very much for all your help, I really appreciate it.

Winter
0
glepizaAuthor Commented:
Thanks!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Drupal

From novice to tech pro — start learning today.