问题
I am making a medical software and I am stuck at a point. I have to make a report section where user will fill up the reports for the patient. The main catch is since the fields/column is variable(less/more). Say if I fill up form in blood test, columns option are different and for X-ray columns is different.
I have made a database so it will store option values for that test id and patient id
CREATE TABLE IF NOT EXISTS `mp_tests_options` (
`test_optn_id` int(11) NOT NULL AUTO_INCREMENT,
`optn_test_id` int(11) NOT NULL,
`optn_patient_id` int(11) NOT NULL,
`test_optn_name` varchar(255) NOT NULL,
`test_optn_value` LONGTEXT DEFAULT NULL,
`test_optn_def_value` LONGTEXT DEFAULT NULL,
PRIMARY KEY (`test_optn_id`),
INDEX (`optn_test_id`),
INDEX (`optn_patient_id`),
FOREIGN KEY (optn_test_id) REFERENCES mp_tests(test_id)
ON UPDATE CASCADE ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
But how do i make the front end for user with proper validation. I dont want to write each form individually.
Thanks for your time.
回答1:
Create a separate table for what columns are required in every form you want.
_______________________________________________
| formName | fields |
|-----------------------------------------------|
| x-ray |field1,field2,field3,field4 |
|-----------------------------------------------|
| bloodtest |field1,field2,field3,field4 |
|_______________________________________________|
And then use explode() it to convert it to array. Also create a table that has possible fields to every form names. Just insert a blank to unneeded fields.
来源:https://stackoverflow.com/questions/23720949/dynamic-form-field-creation-and-saving-in-database-php-mysql