Hi,

I'm working on building my first full drupal module and have run into a few questions. I have the module working with a single block and a user admin page where they can change a couple variables which are stored in the system settings, but I'm looking to move it into a more complete form where the user can add multiple blocks and store the data in a custom table.

Does anyone have an example of this? I've been reading through several modules examples on the drupal site but haven't found what I was looking for.

This is an example of what I have so far:

example1.info
Code:
;$Id$
name = "Example 1"
description = "Adds a block containing with three variables."
core = 6.x
php = 5.1

package = "Examples"
example1.module
PHP Code:
<?php
// $Id: example1.module

/**
* @file
* Module for adding a block with three variables to a page.
*/

/**
 * Create a block for the module.
*/
function example1_block($op 'list'$delta 0$edit = array()) {
    
$blocks = array();
    switch (
$op) {
        case 
'list':
            
$blocks[0]['info'] = t('Example 1');
            break;
        case 
'view':
            
$blocks['subject'] = t('Example1');
            
$blocks['content'] = theme('example1');
            break;
    }
    return 
$blocks;
}

/**
 * Add a template for the block.
 */
function example1_theme($existing$type$theme$path) {
    
$themes['example1'] = array(
        
'template' => 'example1',
        
'arguments' => array('var1'=>'''var2'=>'''var3'=>''),
    );
    return 
$themes;
}

/**
 * Gather all the data and process it before sending to the template.
 */
function template_preprocess_example1(&$vars) {
    
$vars['var1'] = variable_get('example1_var1'null);
    
$vars['var2'] = variable_get('example1_var2'null);
    
$vars['var3'] = variable_get('example1_var3'null);
}

/**
 * Create the admin form.
 */
function example1_admin() {
    
$form = array();
    
$form['example1_var1'] = array(
        
'#type' => 'textfield',
        
'#title' => t('Variable 1'),
        
'#default_value' => variable_get('example1_var1'''),
        
'#size' => 20,
        
'#maxlength' => 20,
        
'#description' => t('A text variable.'),
        
'#required' => TRUE,
    );
    
$form['example1_var2'] = array(
        
'#type' => 'select',
        
'#title' => t('Variable 2'),
        
'#default_value' => variable_get('example1_var2''option1'),
        
'#options' => array('option1'=>'Option 1','option2'=>'Option 2'),
        
'#description' => t('A select variable.'),
        
'#required' => TRUE,
    );
    
$form['example1_var3'] = array(
        
'#type' => 'checkbox',
        
'#title' => t('Variable 3'),
        
'#default_value' => variable_get('example1_var3'0),
    );
    return 
system_settings_form($form);
}

/**
 * Validate user data from admin page.
 */
function example1_admin_validate($form, &$form_state) {
    
$var1 $form_state['values']['example1_var1'];
    
$var2 $form_state['values']['example1_var2'];
    
$var3 $form_state['values']['example1_var3'];
    if(isset(
$var1)) {
        if (!
preg_match('|^[[:alnum:][:space:]]{1,20}$|i'$var1)) {
            
form_set_error('example1_var1't('Only letters, numbers, and spaces are allowed and must be less than 20 characters long.'));
        }
    }
    else {
        
form_set_error('example1_var1't('Variable 1 must be set.'));    
    }
    if(isset(
$var2)) {
        if (!
in_array($var2, array('option1','option2'))) {
            
form_set_error('example1_var2't('Please select an option from the list.'));
        }
    }
    else {
        
form_set_error('example1_var2't('Variable 2 must be selected from the list.'));    
    }
    if (isset(
$var3)) {
        
$var3 true;
    }
    else {
        
$var3 false;
    }
}

/**
 * Add the admin page to the menu.
 */
function example1_menu() {
    
$items = array();
    
$items['admin/settings/example1'] = array(
        
'title' => 'Example 1 Settings',
        
'description' => 'Control the output of example 1\'s block.',
        
'page callback' => 'drupal_get_form',
        
'page arguments' => array('example1_admin'),
        
'access arguments' => array('access administration pages'),
        
'type' => MENU_NORMAL_ITEM,
    );
    return 
$items;
}
example1.tpl.php
PHP Code:
<?php
// $Id: example1.tpl.php,v 0.1 2010/12/29 14:55:00 coyote6 Exp $

/**
 * @file
 * Default theme implementation for example 1 module.
 *
 * Available variables:
 * - $var1: Textfield of 20 Characters only letters and numbers allowed.
 * - $var2: Option1 or Option2 from a select list.
 * - $var3: Checkbox value with true or false set.
 *
 * @see template_preprocess_example1()
 */
?>

<div id="example1-block">
    <p><?php print $var1?></p>
    <p><?php print $var2?> was selected from the dropdown.</p>
<?php
    
if ($var3 == true) {
?>
    <p>The checkbox was checked.</p>
<?php
    
}
    else {
?>
    <p>The checkbox was not checked.</p>    
<?php
    
}
?>
</div>
As I mentioned, I want to be able to put this into a custom table and have it pull multiple blocks created by the user. I believe it is done with the $delta variable but am not sure how. Any help is appreciated. Thanks.