Friday, April 6, 2012

Writing drupal module - Form creation

After 3 days have passed, i finally able to continue my drupal module coding. Today, what i did is creating form elements inside drupal site.

The order of creating form in drupal is like this:

  1. use command 'page callback' where its value is the key function in drupal called drupal_get_form()
  2. use command 'page arguments' whose value is an array that contains a value referring to a name of function (must use underscore in a single word, eg: nama_saya_shahrul. this value - nama_saya_shahrul will be passed to key function drupal_get_form() for drupal to process the form.
  3. Create function nama_saya_shahrul($form, &$form_state), this is just an example.
  4. use variable array that has the followings (make sure you never miss out the hash)


    • #type
    • #title
    • #description
    • #default_value
    • #size
    • #maxlength
    • #required

  5. Need to use another drupal-specific function called variable_get('nama_textfield',default-value). I think variable_get() is similar to session() or assigning value to hidden form field where we can retrieve them later on.
  6. last but not least is using system_settings_form($form) function.

And the following videolog is the output from the new codes

No comments:

Post a Comment