A couple simple tricks to modify a form:

Everyone knows modifying a form can be a pain and particularly confusing for the beginner if you don't know where to start.  I am putting this quick article together to supplement my last article and highlight those tricks.
 

Firebug:

If your looking to modify a form it is a good idea to install Firebug, a plugin for Mozilla's Firefox browser that allows developers to do on the fly CSS, html and other web development.

It is a real time saver and allows you to inspect code by selecting an element instead of peering through lines of code.

Firebug is available here.

Load up your Drupal development site and find a form your wishing to modify.  After installing the plugin and restarting your browser, there should be a little bug icon in the bottom right hand corner.  Press this and select the element that you are looking for.

Firebug and Drupal Development

In the screenshot note that the highlighted value is the form name I had wanted to edit.

A few good pages to have a look at are:

  1. http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6
  2. http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6

 

Simple Module:

I wrote a simple module to lets you know the form and also provides the framework to modify a form.

<?php
// $Id$
/**
* @file
* Modify the Drupal form API
*
*/

/**
 * Implementation of hook_form_alter().
 *
 * The function is named modifyform_form_alter.
 */
function modifyform_form_alter(&$form, $form_state, $form_id) {

  drupal_set_message("Form Id: $form_id");
 
  switch ($form_id) {
    // This is our form ID, use cases in situations where you want
    // to edit more than one form
 
  case 'page_node_form':

//  Put your changes in here

      break;
  }
}

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post PHP code. You should include <?php ?> tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
Navigation
Syndicate
Syndicate content
Share/Save