Im using drupal 6.16. The below code for hook_form_alter is not working. Im simply trying to change the 'Log In' to 'Sign In' on the submit button of the user login form
<?php
//$Id$
function helloworld_form_alter($form_id,&$form) {
switch ($form_id) {
case 'user_login_form':
// Change 'Log in' to 'Sign in'.
$form['submit']['#value'] = t('Sign in');
break;
}
}
Any way to fix this ?
Please help. Thank You.
There are two errors in your code:
yourModuleName_form_alter(&$form, &$form_state, $form_id)
, so in your example the switch on the form id will never trigger.user_login_block
for the small login form available as a block (commonly used on most pages)user_login
for the explicit login page (usually found under 'user/login')Both forms are mostly identical in structure, so you can usually change both within the same hook_form_alter
implementation - just add another case statement to check for the second version.
I find it easier to use theme functions to alter the forms - in your theme's template.php just create this:
function YOURTHEMENAMEHERE_user_login_form($form) {
$form['submit']['#value'] = t('Sign in');
//dsm($form);
return drupal_render($form);
}
the commented out line (dsm) is for the Drupal devel module - which I'd also recommend installing. Once you've installed this and set permissions on your admin role so that you can use it, you'll get a new tab which shows you exactly how the page is constructed and which arrays do what.
Follow the trail within the arrays and you can pretty much theme anything on your site.
EDIT - oh ok :P The one thing I notice, not having used this hook before, is that the example in the API has 3 variables in the function, but you've got 2! Having a mismatch means you're probably being fed the wrong variable:
function modulename_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'contact_mail_page':
$form['submit']['#value'] = t('Sign in');
break;
}
}
For such a trivial change, you should not write a module. The price you pay in terms of performance hit and time wasted is simply to high for the target goal.
You can perform a string replacement that will affect string that are handled by the t() function. This is done is the settings.php configuration file of the site.
Here is how you could replace "Log In" with "Sign In" ...
$conf['locale_custom_strings_en'] = array(
'Log In' => 'Sign In',
);
This will affect the English strings only. Feel free to replace the trailing _en with a specific language code (_fr, _ja, _es) to do the same for other languages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With