简体   繁体   中英

How to save data from dynamically generated textboxes?

I have a page to edit the 'utilization' rate of each employee, based on their designations. So the page has all the designations listed as , next to which a textbox, for the user to fill in the utilization rate. Scenario is that the user will not save each designation's utilization rate immediately after filling it. User will keep going till he fills the last item and then hit the submit button to save. Now, in php I can get all the values from the Request Array. But, how will I know which designations these values belong to? So, what i have as a solution is to name the textboxes with the designation_ids as suffix. May be like;

utilTextbox_1, utilTextbox_2, utilTextbox_3 etc...

Then when the form is submitted;

Check each Request Array element to see if its name starts with 'utilTextbox'

If Yes, split it using '_' to get the designation_id

Update the db table with the value of the text box

Check the next Array Element.....and so on...

is this the correct method or is there a better way of doing this?

You can have array as names in html forms. So something like utilTextbox[1], utilTextbox[2], utilTextbox[3] will work perfectly fine. In php you will get an array in $_REQUEST and you need not to convert in an array because it is already an array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM