How to build a drupal 6 form with out a DB
In this first example i will let you see how to build a simple DRUPAL 6 form with out a DB.
Drupal 6 form
function my_module_hook_form()
{
$form['my_module_name_firstname'] = array(
'#type' => 'textfield',
'#title' => t('The minimum date for to order the cards')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'save'
);
$output = drupal_get_form('my_module_hook_form');
return $output;
}
function my_module_hook_form_validate($form, &$form_state)
{
// your form validation
}
function my_module_hook_form_submit($form, &$form_state)
{
// your form submit and some db insert
}
How to build a drupal 6 form with a DB
In this second example i will let you see how to build a simple DRUPAL 6 form with a DB.
Drupal 6 TableExample
function my_module_hook_form()
{
$query = "SELECT * FROM {my_tablename} WHERE content = '%s'";
$result = db_query($query, $value);
while ($row = db_fetch_object($result))
{
$form['some_standard' . $row->cell_value] = array(
'#type' => $row->cell_type_value,
'#title' => t($row->cell_title_value)
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'save'
);
$output = drupal_get_form('my_module_hook_form');
return $output;
}
function my_module_hook_form_validate($form, &$form_state)
{
// your form validation
}
function my_module_hook_form_submit($form, &$form_state)
{
// your form submit and some db insert
}
How to build a drupal 6 form with table
In this last example i will let you see how to build a simple DRUPAL 6 form with a DB.
Drupal 6 TableExample
function my_module_hook_form()
{
$form['my_module_name_firstname'] = array(
'#type' => 'textfield',
'#title' => t('The minimum date for to order the cards')
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'save'
);
$output = drupal_get_form('my_module_hook_form');
return $output;
}
function theme_my_module_hook_form($form)
{
$rows = array();
$header = array(
array('data' => t('Name'),
array('data' => t('field')
);
$rows[] = array(
t('some name'),
array(
'data' => drupal_render($form['my_module_name_firstname']) ,
'id' => $checkbox_value
),
);
$output = theme('table', $header, $rows);
$output .= drupal_render($form);
return $output;
}
function my_module_hook_form_theme()
{
return array(
'my_module_hook_form_form' => array(
'arguments' => array('form' => NULL),
'file' => 'somefolder/some_file_name.inc',
),
);
}
function my_module_hook_form_validate($form, &$form_state)
{
// your form validation
}
function my_module_hook_form_submit($form, &$form_state)
{
// your form submit and some db insert
}
All drupal 6 form types
| #type |
the explenation |
| checkbox |
This are normal checkboxes |
| date |
This is a date |
| fieldset |
This is not a form but a fieldset for more butifull forms |
| file |
This is a file upload field |
| password |
This is a password field |
| radio |
This is a radio button |
| radios |
This is a mutiple ratio buttons |
| select |
This is a option select field |
| textarea |
This is a textarea |
| textfield |
This is a simple textfield |
| weight |
This is the weight of the form elelment |
All possible vars
#type
checkbox
checkboxes
date
fieldset
file
password
radio
radios
select
textarea
textfield
weight
#access
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#after_build
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#attributes
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#autocomplete_path
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
X |
- |
#base
| |
|
|
|
|
|
|
|
|
|
|
|
#collapsed
| - |
- |
- |
X |
- |
- |
- |
- |
- |
- |
- |
- |
#collapsible
| - |
- |
- |
X |
- |
- |
- |
- |
- |
- |
- |
- |
#cols
| - |
- |
- |
- |
- |
- |
- |
- |
- |
X |
- |
- |
#default_value
| X |
X |
X |
- |
X |
- |
X |
X |
X |
X |
X |
X |
#delta
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
X |
#description
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#disabled
| X |
X |
X |
- |
X |
X |
X |
X |
X |
X |
X |
X |
#field_prefix
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
X |
- |
#field_suffix
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
X |
- |
#maxlength
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
X |
- |
#multiple
| - |
- |
- |
- |
- |
- |
- |
- |
X |
- |
- |
- |
#options
| - |
X |
- |
- |
- |
- |
- |
X |
X |
- |
- |
- |
#parents
| |
|
|
|
|
|
|
|
|
|
|
|
#prefix
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#required
| X |
X |
X |
- |
- |
X |
X |
X |
X |
X |
X |
X |
#return_value
| X |
X |
- |
- |
- |
- |
X |
X |
- |
- |
- |
- |
#rows
| - |
- |
- |
- |
- |
- |
- |
- |
- |
X |
- |
- |
#size
| - |
- |
- |
- |
- |
- |
- |
- |
X |
- |
X |
- |
#suffix
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#theme
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
- |
#title
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#tree
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
#validate
| |
|
|
|
|
|
|
|
|
|
|
|
#weight
| X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
X |
Special Elements
#type
button
form
hidden
markup
item
submit
value
#after_build
| X |
X |
X |
X |
X |
X |
- |
#action
| - |
X |
- |
- |
- |
- |
- |
#attributes
| X |
X |
- |
X |
- |
X |
- |
#built
| - |
X |
- |
- |
- |
- |
- |
#button_type
| X |
- |
- |
- |
- |
X |
- |
#default_value
| - |
- |
- |
- |
- |
- |
- |
#description
| - |
- |
- |
- |
X |
- |
- |
#method
| - |
X |
- |
- |
- |
- |
- |
#parents
| - |
- |
- |
- |
- |
- |
- |
#prefix
| X |
X |
X |
X |
X |
X |
- |
#redirect
| - |
X |
- |
- |
- |
- |
- |
#required
| - |
- |
- |
- |
X |
- |
- |
#return_value
| - |
- |
- |
- |
- |
- |
- |
#submit
| X |
X |
- |
- |
- |
X |
- |
#suffix
| X |
X |
X |
X |
X |
X |
- |
#theme
| X |
X |
X |
X |
X |
X |
- |
#title
| - |
- |
- |
- |
X |
- |
- |
#tree
| X |
X |
X |
X |
X |
X |
- |
#validate
| |
|
|
|
|
|
|
#value
| X |
X |
X |
X |
X |
X |
X |
#weight
| X |
- |
- |
X |
X |
X |
- |