Dynamic form field creation and saving in database php mysql

喜你入骨 提交于 2021-02-11 16:55:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!