tags:

views:

43

answers:

2

I've recently learned OOP in PHP,.. and I though I'd try to write a class in PHP that generates tags for forms i.e. something that lets you generate forms. Its probably been done a billion times before/ or isn't a very good idea. I'm just doing it as an exercise. Anyway, how would I go about planning this?

$form = new Form_Class($formName, $method, $action);

$form->addElement($label, $name, $inputType);

The above two methods are pretty much all I can think of. I won't be adding any validation in this class -- as I think later on I might make a child class for validation.

Thanks in advance for any replies.

A: 

How about adding methods for creating each of the input types such as textbox, password, submit button, etc.

Catfish
What other methods do you think I could add?
john mossel
A: 

Might I suggest putting in some attributes.

$form->addElement($label, $name, $inputType, $attributes);

$attributes would be an array or stdObject containing something like this

$form->addElement('myLabel', 'txtUsername', 'textbox', array('class' => 'css-class'));

Having said that, doing something like this would probably be a little more preferential

$form->textarea($label, $name, $attributes);
$form->textbox(...);
$form->password(...);
castis
What other methods do you think I could add? (sorry about the last comment not making any sense!)
john mossel
aside from textbox, textarea, and password. submit, button, reset, checkbox, radio, dropdown($arrayOfOptions). maybe do something like $form->fieldset($fieldName)->textarea($label, $name, $attr); or something close.
castis