Jump to content

Approach to an html form element generating class


davidannis

Recommended Posts

Long ago I started with a php function that generated an html select list from a mysql table. Over time, I've needed versions that did various things differently (two fields displayed between the <option> and </option> or a div displayed based on the selected value) so I've kept building new versions. Every time I build a new version I think "boy I should make a class and extend it to do things the new way" but I never have and now I must have half a dozen versions of the code. Today I sat down and started coding my class and quickly realized that I need to actually figure out what I put in the parent class and where I draw the line and create another class based on the first. Mostly I code procedural and I could really use some help thinking this through.  Here's what I have in terms of permutations that I want to accomplish:

 

  1. Build an SQL select
    1. set a where clause
    2. set an order by
    3. select multiple columns to concatenate as labels (for example: <option citycode='$cid'>$city, $state, $country</option> )
  2. Build html
    1. Allow list to start with value ='' (eg <option value=''>Choose a state</option> <option value='AK'>Alaska...)
    2. set a selected= value (or values for multiples)
    3. <div> s
      1. No <div> display
      2. Display of a <div> if other is selected
        1. input type=text
        2. textarea
      3. Display of a <div> for each value seected
    4. Types
      1. Select list
        1. single or multiple
      2. Radio
      3. checkboxes

So, do I create a class with methods for each type of html list and a child class for the divs? A parent with the divs and children where I override the method that created the html for radio and checkboxes, something else entirely?

 

Thanks,

David

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.