Ah, this feels great. Finnaly I have taken the step to "show" myself here at the SitePoint forums. I have been a member for some time now but this is actually my first post (except for the presentation post I wrote ages ago).

Well anyways, let's go straight to the point. I have begun writing something I call a "FormGenerator". What I want this application to do is to help me create forms on my websites in a better and easier way. My thoughts is that it - in the future - also will be able to work together with some kind of FormValidation class and maybe some other classes.

Anyways (again) I want some opinions on the class. Is it good or bad, what can I make better, what do you like and dislike about it, should I continue on it or should I throw it in my recycle bin?

I also want to some help here, I have tried to figure out a way to be able to set "selected" attribute on the option-elements in the select-list but I don't know how to do it.

Also I don't like the way I output the form right now. I don't really like that it prints out every element for itself. When I first started coding on this class my plan was to use some kind of output function to print the hole form directly after everything have been set up, but that didn't work very well becuase then I couldn't layout the form as I want with divs and such.

So I want tips and trix on that to

Well here is the code:

And by the way, sorry about my english. I haven't used english in a long time so you'll have to accept my school-english

PHP Code:
<?php
    
/**
     * Generates a form with elements
     * 
     */
    
class FormGenerator
    
{
        
/**
         * Gives the form a unique id
         */
        
private $form_id;
        
        
/**
         */
        
private $form_data;
        
        
/**
         * Decides if the FormGenerators output ($form_data) should be returned (saved) or printed
         */
        
private $output;
        
        
/**
         * Contructs a FormGenerator object
         */
        
public function __construct($output 'return')
        {
            
$this->output $output;
        }
        
        
/**
         * Destructs a FormGenerator object
         */
        
public function __destruct()
        {
            
        }
        
        
/**
         * Sets up a container for a form tag
         */
     
public function openFormContainer($method$name$title$extra$enctype='application/x-www-form-urlencoded')
        {
         
$this->form_data '<form enctype="'.$enctype.'" method="'.$method.'" name="'.$name.'" title="'.$title.'"'.$extra.'>' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Finishes a container for a form tag
         */
        
public function closeFormContainer()
        {
            
$this->form_data '</form>' "\n";
            print 
$this->form_data;
            
        }
        
        
/**
         * Groups related form elements
         */
        
public function openFieldset($extra=null)
        {
            
$this->form_data '<fieldset'.$extra.'>' "\n";
            print 
$this->form_data;
        }
        
        
/**
         */
        
public function closeFieldset()
        {
            
$this->form_data '</fieldset>' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Specifies a description for a fieldset
         */
        
public function addLegend($align='top'$value$extra=null)
        {
         
$this->form_data '<legend align="'.$align.'"'.$extra.'>'.$value.'</legend>' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Provides identifying text for a form widget
         */
        
public function addLabel($for$value$extra=null)
        {
         
$this->form_data '<label for="'.$for.'" title="'.$title.'"'.$extra.'>'.$value.'</label>' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Identifies several input methods for forms
         */
        
public function addInput($name$type$extra=null)
        {
         
$this->form_data '<input name="'.$name.'" type="'.$type.'"'.$extra.' />' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Specifies a selection list within a form
         */
        
public function addSelect($name$options$extra=null)
        {
            
$this->form_data '<select name="'.$name.'"'.$extra.'>' "\n";
            
            foreach (
$options as $option_value => $option_item)
            {
          
$this->form_data "\t" '<option value="'.$option_value.'"'.$extra.'>'.$option_item.'</option>' "\n";
            }
            
            
$this->form_data '</select>' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Defines a multiple-line text input field within a form
         */
        
public function addTextarea($name$value=null$extra=null)
        {
         
$this->form_data '<textarea name="'.$name.'"'.$extra.'>'.$value.'</textarea>' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Sets up a button to submit or reset a form as well as to activate a script
         */
        
public function addButton($name$type$value$extra=null)
        {
         
$this->form_data '<button name="'.$name.'" type="'.$type.'" value="'.$value.'"'.$extra.' />' "\n";
            print 
$this->form_data;
        }
        
        
/**
         * Sets up a premade submit button
         */
        
public function addSubmitButton($name$value$extra=null)
        {
         
$this->form_data '<input name="'.$name.'" type="submit" value="'.$value.'"'.$extra.' />' "\n";
            print 
$this->form_data;
        }
        
        
/**
         */
        
public function output()
        {
            if (
$this->output == 'print')
            {
                print 
$this->form_data;
                return 
1;
            }
            elseif (
$this->output == 'return')
            {
                return 
$this->form_data;
            }
        }
        
    }
    
    
$form = new FormGenerator('print');
    
    
$form->openFormContainer('post''myTestForm''Fill in my test form''');
    
    
$form->openFieldset();
    
$form->addLegend('top''My Test Form');
    
    print 
'<p>' "\n";
    
$form->addLabel('first_name''First Name');
    
$form->addInput('first_name''text');
    print 
'</p>' "\n";
    
    print 
'<p>' "\n";
    
$form->addLabel('last_name''Last Name');
    
$form->addInput('last_name''text');
    print 
'</p>' "\n";
    
    print 
'<p>' "\n";
    
$form->addLabel('password''Password');
    
$form->addInput('password''password');
    print 
'</p>' "\n";
    
    
$console_options = array (
        
'nes' => 'Nintendo 8-bit',
        
'snes' => 'Super Nintendo (16-bit)',
        
'saturn' => 'Sega Saturn',
        
'playstation' => 'Playstation',
        
'dreamcast' => 'Dreamcast',
        
'n64' => 'Nintendo 64'
    
);
    
    print 
'<p>' "\n";
    
$form->addSelect('consoles_you_own'$console_options);
    print 
'</p>' "\n";
    
    
$form->closeFieldset();
    
    
$form->addSubmitButton('send_data''Login to My Realm');
    
    
$form->closeFormContainer();
    
    
?>