Jump to content
Sign in to follow this  
hoangtaybaokiem1993

[Bao Kim]Saving data from all text boxes in one click

Recommended Posts

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?

Bảo Kim

Share this post


Link to post
Share on other sites

use an array for the form field name, with the id as the array index - <input type='text' name='utilTextbox[1]'> <input type='text' name='utilTextbox[2]'> ...

when the form is submitted, you can loop over the array of data to get the id and the value -

foreach($_POST['utilTextbox'] as $id=>$value)
{
	echo "id: $id, value: $value<br>";
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.