Welcome Guest, Not a member yet? Register   Sign In
[solved] multiple form elements in foreach?
#1

[eluser]Matalina[/eluser]
I don't know why its happening. Here's the code, I'll explain the problem after that:
View Code:
Code:
<h2>Order Form</h2>
&lt;?php
  if(!empty($order)) {
    ?&gt;
    &lt;?php
    $id = 0;
    foreach($order as $vendor => $item) {
      ?&gt;
        <table>
        <tr>
          <th colspan="4">&lt;?php echo $vendor;?&gt;</th>
        </tr>
      &lt;?php
      foreach($item as $store => $row1) {
        ?&gt;
          <tr>
            <th colspan="4">Store #&lt;?php echo $store;?&gt;</th>
          </tr>
          <tr>
            <th>Qty</th>
            <th>Item</th>
            <th>Price</th>
            <th>SubTotal</th>
          </tr>
        &lt;?php
        foreach($row1 as $row) {
          $id++;
          ?&gt;
            <tr>
              <td>&lt;?php echo form_input('order'.$id,set_value('order'.$id,1),'size="3" maxlength="3" class="order"').form_hidden('price'.$id,$row['StandardCost'],'class="price"');?&gt;</td>
              <td>&lt;?php echo $row['BrandName'].' '.$row['ModelNumber'].'<br/>'.$row['ModelDescription'];?&gt;</td>
              <td>&lt;?php echo '$'.number_format($row['StandardCost'],2);?&gt;</td>
              <td class="subtotal">&lt;?php echo '$'.number_format($row['StandardCost'],2);?&gt;</td>
            </tr>
          &lt;?php
        }
      }
      ?&gt;
        </table>
      &lt;?php
    }
    ?&gt;
    &lt;?php
  }
  else {
    ?&gt;
      <div class="alert-box warning">There is nothing to order at this time.</div>
    &lt;?php
  }
?&gt;

Actual HTML output for second row:
Code:
<td>&lt;input type="text" name="order2" value="1" size="3" maxlength="3" class="order"&gt;&lt;input type="hidden" name="price1" value="237">
&lt;input type="hidden" name="price2" value="264"&gt;
</td>

I should only have one hidden input. I don't have two text inputs, so I'm at a lost of why the hidden field is getting added twice. Note: The third row will display 3 hidden fields.

#2

[eluser]Matalina[/eluser]
The extra parameter in hidden caused the problem.




Theme © iAndrew 2016 - Forum software by © MyBB