www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] How to process a Invoice form?

  1. #1
    Join Date
    Jun 2010
    Posts
    16

    resolved [RESOLVED] How to process a Invoice form?

    Hi, I'm having a problem. I'm doing an Invoice system. So basically the user can enter the Item name, cost, quantity and total will be auto calc using javascript.

    Currently, I'm adding a iteration behind each input to differentiate them. E.g.
    Code:
    <input type ="text" name = "Item<?=$i?>"/>
    $i is an iteration using for loop.

    My problem is, how to process it at the php side?

    $itemName = $_POST['Item'];

    I can't possibly hardcode it for the name inside post to be $_POST['Item1'], $_POST['Item2'], $_POST['Item3']....
    If there are more than 10 items, it's too long. Any help?

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    if you give the inputs the same name, they should be sent to the $erver as an array when you submit the form and you can then loop through the array on the $erver as you would with any other array.

    Code:
    <input type ="text" name = "Item[]" />
     
    <input type ="text" name = "Item[]" />

  3. #3
    Join Date
    Jun 2010
    Posts
    16
    So my $erver side code should be

    Code:
    $item = $_POST['Item[]'];

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    Your client side code could be something like this:

    Code:
     
    <form action="formProcessor.php" method="post" >
     
           <input type="text" name="myTxt[]" />
           <input type="text" name="myTxt[]" />
    
            <input type="submit" value="submit" />
     
    </form>
    and formProcessor.php could be something like this:


    PHP Code:
    <?php
     
    //assing the values from the textboxes to an array
    $inpArray $_POST['myTxt'];
     
    //loop thru the array to display all the textbox values
    foreach($inpArray as $key => $value)  {
         echo 
    $key.' '.$value.'<br />';
    }
     
    //display the value in the first etxbox
    echo 'value of first input = '.$inpArray[0];
     
        
    ?>

  5. #5
    Join Date
    Jun 2010
    Posts
    16
    Hey thanks! That really worked out. Thanks lots!
    Last edited by monstez88; 06-24-2010 at 12:11 AM.

  6. #6
    Join Date
    Mar 2010
    Posts
    2,803
    no problem - happy to help

  7. #7
    Join Date
    May 2010
    Location
    Manila, Philippines
    Posts
    189
    that's tirna's final signature "no problem - happy to help "

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles