Drupal Forms Archives - developed.be

This tutorial explains how to created a single page with a login form an a register form in Drupal6.

developed_loginregister

To accomplish this, we have to go through some concepts first:

Continue reading “A custom login/register page for Drupal 6″…

This function will print a large list of all the variables that are declared in the current scope:

<?php print_r(get_defined_vars()); ?>

An interesting variable is $node, but it is not always accessible.

 

The short answer:

It’s not possible

The long answer:

In a simple user form it is possible to add a single on/off checkbox.

  $form['thermometer_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show the thermometer'),
    '#options' => array(0 => t("no"), 1 => t("yes")),
  );

But, it’s not possible to provide a default value (checked/unchecked) with a single chechbox. This causes difficulties when you want to show the saved value of a user.

A simple solution is to use a “yes/no radiobutton list” instead of a single checkbox.

  $form['thermometer_enabled'] = array(
    '#type' => 'radios',
    '#title' => t('Show the thermometer'),
    '#options' => array(0 => t("no"), 1 => t("yes")),
    '#default_value' => variable_get('thermometer_enabled', 0),
  );

In this example the result is saved in the variable thermomoeter_enabled and has the default value of 0 (false).