template.php

How to Remove the Colon After Field Labels

Sometimes you need to remove the colon that is printed by default after all field labels. For instance in webforms you might be asking a question such as 'What is your favorite color?:' See how ridiculous the colon looks after the question mark?

Let's get rid of that.

Load external js file in Drupal 6

I found this little snippet today and what a help it is. Put this in your template.php file and you can load JavaScript files from an external source.

$external_js = 'http://www.example.com/a.js';
drupal_add_js('document.write(unescape("%3Cscript src=\''.
$external_js .
'\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline');

*Note: I formated the above to display correctly on this page.

Rearrange Form Elements in template.php

I want to change the way the 'Add Page' form appears. In order to override the default page form, you'll have to register your own theme function in either a module or inside template.php.

I am going to use template.php. To get the internal name of the form, just view the html source of your 'Add Page' page and search for 'form_id'. The form_id of the form we're after is 'page_node_form'.

function garland_theme () {
  return array(
    'page_node_form' =>  array(
      'arguments' => array('form' => NULL),
    ),
  );
}

I have registered the function. Note the form_id and the fact that $form should be passed as an argument.

Now I will create the overriding function that will be called instead of the default page_node_form. My function here is not very useful. It's only intended to illustrate how to do these things. What I'm going to do is move the 'title' field below the 'body' field. And while I'm at it I will change the label above the body field to include the users fullname. Fullname is a field I included in the user profile.

function garland_page_node_form($form) {

Syndicate content

Contact Me

Feel free to contact me.

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.