Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting Postback values from Dynamic Checkboxes

    Hello,

    I am trying to make an online sandwich order form. So I have different lunch meats, bread, condiments and so on in mysql database. Everything I created is drop down box, however I have the condiments listed as checkboxes that are dynamically driven by another table. Here is the code for the checkboxes. When the user hits submit it shows on the users screen what they ordered for a sandwich and sends an email to our deli. Everything works except the condiments - as I do not know how to capture the value into a php variable. Should I use an array to do this sense the number of condiments could increase or decrease? Here is the code for selecting the condiments.
    [CODE]
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td align="center" valign="top"><strong>Condiments</strong><br>
    <table width="399" cellpadding="0" cellspacing="0">
    <?php do { ?>
    <tr>
    <td width="180" align="right" valign="middle" bgcolor="#FFFFFF"><?php echo $row_condiment['condiment']; ?>
    <input name="c1" type="checkbox" id="c5" value="<?php echo $row_condiment['condiment']; ?>" /></td>
    <td width="20" align="left">&nbsp;</td>
    <?php $row_condiment = mysql_fetch_assoc($condiment) ?>
    <td width="180" align="left" valign="middle" bgcolor="#FFFFFF"><input name="c2" type="checkbox" id="c4" value="<?php echo $row_condiment['condiment']; ?>" />
    <?php echo $row_condiment['condiment']; ?></td>
    </tr>
    <?php } while ($row_condiment = mysql_fetch_assoc($condiment)); ?>
    </table>
    [ICODE]
    Hope this makes sense - sorry I am a newb still haha.

    Thank you,
    Dale

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,549
    Thanks
    8
    Thanked 1,095 Times in 1,086 Posts
    Your checkbox name should be like this: name="cond[]"
    That creates an array for all of the checkboxes.

    <input name="cond[]" type="checkbox" id="c5" value="<?php echo $row_condiment['condiment']; ?>" /></td>

    When it's posted to the script that processes the form,
    you will then loop through and read that array. Only the
    items that were checked will exist, and the value of the
    array element will be the value of the checkbox,
    example, $condiments[1] might be "Onions".

    To read your checkbox array ... would be similar to this ...
    PHP Code:
    // read the checkbox array
    $condiments=$_POST['cond'];
    while (list (
    $key,$val) = @each ($condiments)) {
    // do something with the value here.
    // maybe create another array to use later on?
    // for now, just echo to see what was selected.
    echo $val."<br>";


  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow! Awesome Thank you so much!

  • #4
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That worked awesome!!!

    Everytime I think I start to learn this php thing I run into another issue.

    Kind of an offtopic question but sort of similiar...

    I am creating an order form with dynamic rows..
    so I have

    Bread Type | Price |Quantity ordered

    Price and quantity ordered are textboxes. So if I name Price - "price[]" and "quantity[]" will I be able to take individual values? What I am really trying to do is post back the Quantity ordered for each row - and also multiply each rows price by quantity ordered and add all of the rows to get a total

    Anyone know of an example tutorial / code similiar to this I can look at?

  • #5
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont know if I explained myself very well..


    basically I am just wondering how I can name ids in a dynamic table.

    so in row 1 I want textbox1 id = textbox1 and in row 2 I want textbox2 id = textbox2 and so on so I can use these values

  • #6
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm nvm its not pretty but I think I found a solution to my question.


  •  

    Posting Permissions

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