Jump to content

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?

 

 

 

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 by Frank_b
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.