在MySQL数据库中指定HTML输入属性?

I'm trying to create a dynamic form creation function using PHP at the moment. I'm trying to make it as non-dependent as possible.

In doing this, I wanted to specify HTML input types in the database itself. I started with things like 'if varchar, then create a text field' type thing. But I realized that I would run into problems with radio button, check box, password and email fields.

Is there any way to create an attribute for the column that contains a number relating to another table that will specify what kind of input it will be?

Here's an example table setup:

id - email - password - first_name - last_name - gender - terms_accepted

Then I would have numbers relating to another table as attributes so it would be something like this:

id - email - password - first_name - last_name - gender - terms_accepted

null - 1 - 2 - 3 - 3 - 4 - 5

And the other table would be something like this:

type_id - type_name

1   =        email

2     =      password

3    =       text

4      =      radio button

5       =  check box

Is something like this possible? or should I come back to reality? What would it look like if possible, and how would I execute such a structure?

Too long for a comment but probably not a complete answer either. This is based on the idea of dynamic database table -> html form conversion. On your first, "if varchar then..."

I actually created something similar to this already but rarely use it because using HTML templates for forms just makes more sense in most situations. Sure it might take a little bit more time initially but on a web site you sometimes want forms with a specific order or certain parts split up. Then you have language issues or variable names. For instance when you have 0 or 1 in the database, does it mean 0/1, does it mean true/false, does it mean yes/no? With an enum() or varchar() you should have short fields like "id" but maybe you want the HTML form to say "Identification". Lastly, it creates less load on your web server because instead of consulting the database and script constantly, you're just reading in a static HTML file. Just my two cents.

But in essence, radio buttons are pretty outdated, usually a select menu is sufficient and saves space on the page. In my script, I used selects for all ENUM fields. To distinguish between a select and a checkbox, you would have to look up the mysql table details to read into the foreign key. You are not thinking enough about the database structure. You should be trying to conform a script to how a proper database structure would be, not the other way around. A checkbox would be a many-to-many relationship, a radio/select would be a one-to-many.

This is the general way I would go about it:

field # a list of all fields
  id int PK
  field_type_id int FK

field_type # an enum of all field types
  id int PK
  field_name varchar(32)

field_data # all saved field data, keyed by field id
  id int PK
  field_id int FK
  field_data blob,etc.

NB - I wouldn't store user data in such a format.