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.
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.
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:
- http://api.drupal.org/api/drupal/developer--topics--forms_api.html/6
- 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;
}
}