2

drupal_set_title doesn't work in my case. well... it worked some time ago (i don't remember when it stopped working) but after installing couple (4-6) of modules it stopped working. where else i can override page-title? it really bugs when you see 'Create Add new order' instead of 'Order form'... so i can live with that but it BUGS me every time i go to that page....

function driver_mailer_form_alter(&$form, &$form_state, $form_id) {
global $user;
if (!empty($form['type']['#value']) && $form['type']['#value'] == 'order') {
drupal_set_title(t('Order form'));
}

one more thing, if i do code like this

function driver_mailer_form_alter(&$form, &$form_state, $form_id) {
global $user;
drupal_set_title(t('Order form'));
if (!empty($form['type']['#value']) && $form['type']['#value'] == 'order') {
}

it works but it changes page-titles to all my pages (((

and if its possible i really don't want work with .tpl files (i don't know how to yet), but if thats the only way in my case please provide sort of short tutorial.

THANKS to everyone for help!!!!!

I did try to weight my module... made a file 'driver_mailer.install' and used this code:

<?php
/**
* Implements hook_install().
*/
function driver_mailer_install() {
db_update('system')
->fields(array('weight' => 100))
->condition('name', 'driver_mailer')
->execute();
}
?>

then i turned off my module, flush my caches, and turned my module back... nothing changed... not working.))))

4

finally...

in general code below works great...

function yourmodulename_form_alter(&$form, &$form_state, $form_id) {
if (!empty($form['type']['#value']) && $form['type']['#value'] == 'yourcontenttype') {
drupal_set_title(t('my title'));
}
}

BUT sometimes other modules do altering the form and title AFTER your module... that was my case :( it took me couple days to find the solution... solution:

function yourmodulename_preprocess_page(&$variables) {
if (!empty($variables['page']['content']['system_main']['#form_id']) && $variables['page']['content']['system_main']['#form_id'] == 'yourcontenttype_node_form'){
drupal_set_title(t('my title'));
}
}

to find out your form's id use this in form_alter

drupal_set_message(print_r($form_id, true));

I hope someone will find it useful...

  • I certainly found it useful. Thank you very much indeed. – Frank H. May 6 '15 at 21:23
1

If the first way you code your form_alter doesn't work, but the second does, that suggests to me that your form has changed, because the only thing I see different is your if is failing. To figure this out some more, a little debugging might help out:

function driver_mail_form_alter(&$form, &$form_state, $form_id) {
  global $user;

  drupal_set_message('Altering ' . $form_id);  // take this out when you figure out what $form_id you are looking for
  if ($form_id=='new_order_node_form') {       // or whatever the machine name of your node type you are looking for is plus _node_form or some such 
    drupal_set_title(t('Order form'));
  }

  // whatever else here

}

If, however, this still doesn't work, this means (or suggests) that one of the 4 or 6 modules you added is altering the form and title AFTER your module. IF this is the case, then you'll have to weight your module so as to run after that module.

  • I did check $form_id many times with drupal_set_message before asking experts. – Forey Vitaliy Feb 5 '13 at 15:09
  • I didn't try to weight my module. how can i do that? – Forey Vitaliy Feb 5 '13 at 15:10
  • in D6, you would go into the system table in your database and update the weight field of your module to be a greater number than the module you want to override. I don't know precisely how to do it in D7. BUT... if the second way, eg, you are drupal_set_title()ing without condition in your form_alter AND that is working, that suggests that something else less serious is going on. – Jimajamma Feb 5 '13 at 15:29
  • This method doesn't work when form validation fails as the form_alter()s are cached by Drupal and not re-run (in D7 at least). – Justin Apr 1 '14 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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