Contact

If you like a new Web or Desktop
application, update a existing one
or add new modifications. Your at
the right place and hit the
hire me button

Follow

If your intersted you can follow
me on Twitter by clicking here

Web and Apps Building Refernce World Wild Web UNIX Apps AND Tips Programming languages

Build a drupal 6 form

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 #after_build #attributes #autocomplete_path #base #collapsed #collapsible #cols #default_value #delta #description #disabled #field_prefix #field_suffix #maxlength #multiple #options #parents #prefix #required #return_value #rows #size #suffix #theme #title #tree #validate #weight
X X X X X X X X X X X X
X X X X X X X X X X X X
X X X X X X X X X X X X
- - - - - - - - - - X -
                       
- - - X - - - - - - - -
- - - X - - - - - - - -
- - - - - - - - - X - -
X X X - X - X X X X X X
- - - - - - - - - - - X
X X X X X X X X X X X X
X X X - X X X X X X X X
- - - - - - - - - - X -
- - - - - - - - - - X -
- - - - - - - - - - X -
- - - - - - - - X - - -
- X - - - - - X X - - -
                       
X X X X X X X X X X X X
X X X - - X X X X X X X
X X - - - - X X - - - -
- - - - - - - - - X - -
- - - - - - - - X - X -
X X X X X X X X X X X X
X X X X X X X X X X X -
X X X X X X X X X X X X
X X X X X X X X X X X X
                       
X X X X X X X X X X X X

Special Elements

#type button form hidden markup item submit value #after_build #action #attributes #built #button_type #default_value #description #method #parents #prefix #redirect #required #return_value #submit #suffix #theme #title #tree #validate #value #weight
X X X X X X -
- X - - - - -
X X - X - X -
- X - - - - -
X - - - - X -
- - - - - - -
- - - - X - -
- X - - - - -
- - - - - - -
X X X X X X -
- X - - - - -
- - - - X - -
- - - - - - -
X X - - - X -
X X X X X X -
X X X X X X -
- - - - X - -
X X X X X X -
             
X X X X X X X
X - - X X X -