SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    generate multiple forms

    Hey guys, I plan on using a quanity input field to specife the quanity of a product they wish to buy.

    What i would like to do is this:
    1. User clicks which product they want (lets say productid=1)
    2. User enters the quanity they wish to purchased (lets say '2')
    3. User selects if they would like the company to install this product.
      • The user choose 2 as the quanity. So they will see 2 checkbox options to choose if they want the company to install both products, one of the products or none of the products. (<input type="checkbox" name="install_productid_1_quanty_2" value="1" />Product Name #</input>)
    4. User sees total invoice. Lets say the user choose to have the company install both
      • Product Name #1 (Price)
      • Product Name #2 (Price)
      • Install Product Name #1 (Price)
      • Install Product Name #2 (Price)
      • (Total)


    The only problem i'm having is generating the mutiable forms and keeping the variables orginized to tally the total at the end. Any ideas would be great. Thanks a million!

    LiveWire

  2. #2
    SitePoint Member natural mystic's Avatar
    Join Date
    Jul 2005
    Location
    Los Angeles, CA
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you can do something like
    Code:
    $quant = quantity-goes-here;
    $current = 1;
    
    while ($current <= $quant)
    {
    $current++;
    echo "<input type="checkbox" blah blah>";
    }

  3. #3
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks works perfect!

  4. #4
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more question, if a user has 5 as the quanity. How would i generate a number list. Like

    #1
    #2
    #3, ect...

    Can i use foreach ();?

  5. #5
    SitePoint Member natural mystic's Avatar
    Join Date
    Jul 2005
    Location
    Los Angeles, CA
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With this script, since $current is the amount that you are currently on, you can just use this instead of the previous echo statement you had:

    PHP Code:
    echo "#{$current} <input type="checkbox" blah blah>"

  6. #6
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, almost what i needed. I had to do this:
    PHP Code:
            while ($current <= $quant)
            {
                    
    $current++;
                    
    $number $current 1;
                    echo 
    "#{$number} <input type=\"checkbox\"><br />";
            } 
    Thanks!!

  7. #7
    SitePoint Member
    Join Date
    Aug 2003
    Location
    Iowa
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by putting current++ at the end of the loop you can take the extra line out.
    PHP Code:
            while ($current <= $quant)
            {
                    echo 
    "#{$current} <input type=\"checkbox\"><br />";
                    
    $current++;
            } 

    but both will work.

  8. #8
    SitePoint Member natural mystic's Avatar
    Join Date
    Jul 2005
    Location
    Los Angeles, CA
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My bad, Aku is correct. You can still use my original script, just change $current = 1; to $current = 0;

    you can do this, or just listen to Aku, and keep it at 1, and use the count++ at the end of the while loop.

  9. #9
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    Florida
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, everything you suggested worked perfectly and i can't thank you guys enough!


Bookmarks

Posting Permissions

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