i'm trying to:

        custom theme my user_login form
                AND
        add a custom validation step to my user_login form

rather than re-inventing the wheel, i'm following the theming method @

        "Theming the Drupal 6 User Login Form"
         
http://blog.aphexcreations.net/2009/04/theming-drupal-user-login-form.html

and the Authentication example @,

        "Pro Drupal Development"
         Ch6: External Login: Simple External Authentication


i'm confused about their combination -- specifically, getting the
themeable login form to USE the custom login authenticator.


so far i've:

added to a custom.module

        ...
        function custom_theme() {
                return array(
                        'user_login' => array(
                                'template' => 'user-login',
                                'arguments' => array('form' => NULL),
                        ),
                );
        }
        function custom_user_login(&$variables) {
                $variables['rendered'] = drupal_render($variables['form']);
        }
        ...

as well as the form element "breakout" function,

        ...
        function get_user_login_form() {
                $form_id = 'user_login';
                $form = array();
                $form['name'] = array(
                        '#type' => 'textfield',
                        '#maxlength' => USERNAME_MAX_LENGTH,
                        '#required' => TRUE,
                        '#attributes' => array('tabindex' => '1'),
                ...
                $form['#validate'] = user_login_default_validators();
                $form['#build_id'] = sprintf('form-%s', md5(uniqid(mt_rand(), 
TRUE)));
                ...
                return $out;
        }
        ...

in my user-login.tpl.php, i have

        ...
        <div>
                TESTING 1 2 3 TESTING 1 2 3
                <?php $login_form = get_user_login_form(); ?>
                <?php print $login_form->form_start; ?>
                <div><?php print $login_form->name; ?></div>
                <div><?php print $login_form->pass; ?></div>
                <div><?php print $login_form->submit; ?></div>
                <?php print $login_form->form_end; ?>
        </div>
        ...

which DOES display correctly @ "user/login". that's good.

from "Pro Drupal Development", I'm adding a custom validation step ...
in my custom.module:

        ...
        function custom_form_alter(&$form, $form_state, $form_id) {
                switch ($form_id) {
                        case 'user_login':
                        case 'user_login_block':
                                // If the user login form is being submitted, 
add our validation
                                if (isset($form_state['post']['name'])) {
                                        // Find the local validation function's 
entry so we can replace it
                                        $array_key = array_search(
                                                
'user_login_authenticate_validate',
                                                $form['#validate']
                                        );
                                        if ($array_key === FALSE) {
                                                // Could not find it. Some 
other module must have run form_alter()
                                                // We will simply add our 
validation just before the final validator
                                                $final_validator = 
array_pop($form['#validate']);
                                                $form['#validate'][] = 
'custom_login_validate';
                                                $form['#validate'][] = 
$final_validator;
                                        } else {
                                                // Found the local validation 
function. Replace with ours.
                                                $form['#validate'][$array_key] 
= 'custom_login_validate';
                                        }
                                }
                                break;
                }
        }
        ...

But, what gets used/displayed by my user-login.tpl.php continues to
use the 'standard' authenticator, NOT my custom one.

I suspect that's because of:

        @ function custom_form_alter  -->
                $form['#validate'][$array_key] = 'custom_login_validate';

"versus"

        @ function get_user_login_form  -->
                $form['#validate'] = user_login_default_validators();


They likely need to be sync'd up.

My question is -- how?

Any pointers appreciated.

Ben

Reply via email to