harilalmn Posted December 19, 2014 Share Posted December 19, 2014 Hi All, this is my first post after joining the forum. First of all, I am not a programmer. My field is of Building design and Architecture. I work for an Architectural company. I have a great interest in programming and I started learning php, mysql, html css and jscript, to develop a timesheet application for the company. The web application was created and successully implemented in April this year...! However, all these are purely 'self learning', and it has its own downsides as well. This was just a small intro..., let me come to what i request help on. This is for further development of the application. 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 <labels>, 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? Quote Link to comment https://forums.phpfreaks.com/topic/293175-saving-data-from-all-text-boxes-in-one-click/ Share on other sites More sharing options...
Frank_b Posted December 19, 2014 Share Posted December 19, 2014 (edited) Take a look at this little working example: <?php if($_SERVER['REQUEST_METHOD'] == 'POST') // check if the form has been submitted { for($i = 0 ; $i < count($_POST['id']) ; $i++) { echo 'id '.$_POST['id'][$i].' has name '.$_POST['name'][$i].'<br>'; } } ?> <html> <head> <title>test</title> <meta charset="UTF-8"> </head> <body> <pre><?php print_r($_POST); ?></pre> <form action='' method="post"> <input type='hidden' name='id[]' value='1' /> <input type='text' name='name[]' value='Frank' /> <input type='hidden' name='id[]' value='2' /> <input type='text' name='name[]' value='Joop' /> <input type='hidden' name='id[]' value='5' /> <input type='text' name='name[]' value='Carl' /> <input type='submit' value='Send' /> </form> </body> </html> Edited December 19, 2014 by Frank_b Quote Link to comment https://forums.phpfreaks.com/topic/293175-saving-data-from-all-text-boxes-in-one-click/#findComment-1500060 Share on other sites More sharing options...
mac_gyver Posted December 19, 2014 Share Posted December 19, 2014 you would just use the id value as the form element's array index value - name = 'utilTextbox[1]' when you loop over the submitted for data for that element, the array key is the id, the array value is the submitted value. Quote Link to comment https://forums.phpfreaks.com/topic/293175-saving-data-from-all-text-boxes-in-one-click/#findComment-1500083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.