Jump to content

Approach to an html form element generating class


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?




Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.