Jump to content


Approach to an html form element generating class

class methods inherritance

  • Please log in to reply
No replies to this topic

#1 davidannis


    Freak Dr.

  • Members
  • PipPipPip
  • 463 posts
  • LocationOkemos, MI USA

Posted 02 April 2013 - 11:19 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime