0

Is it possible to create own login form? I need to insert it into my basic page. It is campaign for my client and he wants to be able login from specific basic page. I have tried to use block from classic login, but without success. But it still has many things around (like remember me etc..), and I need only basic username/password

thanks for any help

2 Answers 2

1

You should be able to just retrieve the form and print it on your node template. In your theme's template.php (a custom module would work too):

function MYTHEME_preprocess_node(&$variables) {
    if ($variables['view_mode'] == 'full' && $variables['nid'] == 9 && user_is_anonymous()) {
        $variables['login_form'] = drupal_get_form('user_login');
    }
}

And then in either your theme's node.tpl.php or a specific node template if you're using one:

<?php if (isset($login_form)): ?>
  <?php print render($login_form); ?>
<?php endif; ?>

This will just print the same form you'd find at /user/login wherever you want it. Just make sure to replace the 9 with your node's nid.

4
  • Thank you, this is prefect first step. But it render login form with many fields around (header, perex, remember me... etc.). I need only username and password. Is it possible to achieve this without css hidding? Next think is redirection if I fill in wrong password, it redirects me to login page. edit: it is inserting what is in user-login.tpl.php
    – Dawe
    Feb 18, 2015 at 9:32
  • Maybe by creating if statement inside user-login.tpl.php, but then I need to pass there some variable from call " drupal_get_form('user_login');" to recognize that this login form is for my specific page. I can not use node id here because I have there another login form in popup. Is it possible to pass some argument?
    – Dawe
    Feb 18, 2015 at 10:41
  • Try adding a couple lines to the hook_preprocess_node, one to change the theme - note the goal here is to not use your user-login.tpl.php, and just render the basic form without a template - and one line to add a destination to your form: $variables['login_form']['#action'] .= '?destination=' . current_path(); $variables['login_form']['#theme'] = '_custom';
    – thumbson
    Feb 18, 2015 at 15:51
  • I have solved it a little bit different way. In hook_preprocess_node I just added: $variables['login_form'] = drupal_get_form('user_login', "my_identificator");... Then in hook_form_alter I added if(reset($form_state['build_info']['args']) == "my_identificator"){. So when is this if fullfiled, then I set $form['login_type'] = array('#markup' => "my_identificator");. Then in user-login.tpl.php I have if block if(isset($form["login_type"]) && isset($form["login_type"]["#markup"]) && $form["login_type"]["#markup"] == "my_identificator") { ?> where I render all what I need.
    – Dawe
    Feb 19, 2015 at 18:46
1

Or, if you're looking for a way to do it without writing code, consider the Login Toboggan module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.