1

I can't create HTML form in a php loop in a function. Here what I did:

    foreach ($products as $product) {

            $html .= "<tr>
                <form method='POST' id='form-".$product->virtuemart_product_id."' class='product js-recalculate' action = '' >";

                $html .="<td>".$product->product_s_desc."</td>";                

                if($showattribute == 1) {
                    $html .="<td class='product_attribute' id='PerUnitAttr".$product->virtuemart_product_id."'>";

                        if (!empty($product->customfieldsCart)) {

                            foreach ($product->customfieldsCart as $field) {

                                $html .= "<p><b>". $field->custom_title."</b></p>";
                                $html .= "<p>". $field->display."</p>";

                            }

                        }
                    $html .= "</td>";
                }
        $html .= 
                '<td><span class="quantity-box">
                <input type="text" class="quantity-input" id="PerUnitQuantity'.$product->virtuemart_product_id.'" name="quantity[]" value="1"/>
                </span>
                <span class="quantity-controls">
                    <input type="button" id="PerUnitPlus'.$product->virtuemart_product_id.'" class="quantity-controls quantity-plus"  />
                    <input type="button" id="PerUnitMinus'.$product->virtuemart_product_id.'" class="quantity-controls quantity-minus" /> 
                </span>
                <input type="hidden" class="pname" value="'. $product->product_name .'"/> 

                ';


            $html .="<td><span style='margin-left: 8px;' id='PerUnitTotal".$product->virtuemart_product_id."'> 0 </span> ".$currency->getSymbol()."</td>
</form></tr>";
}
return $html;

But that form not showing up & inserting closing tag before in where I ended it. It's something like this:

    <tr>

        <form id="form-72" class="product js-recalculate" action="" method="POST">
        </form>
        <td></td>
<tr>

    <form id="form-6" class="product js-recalculate" action="" method="POST"></form>
    <td></td>

In where I did mistake ?

For more specific what I wanted to do the output will be like this:

<table>
loop start
<form action='' id='id='form-".$data."'>
<tr>
<td></td>
</tr>
</form>
loop end
</table>

But output not showing correctly.

4
  • 2
    you notice that you didn't close off your first echo --> $html .= "<tr> <form method='POST' id='form-".$product->virtuemart_product_id."' class='product js-recalculate' action = '' >? You're missing a ";. Commented Jul 23, 2014 at 3:20
  • Sorry I didn't noticed that but it was correct. During asking question I reduced code that time it was mistake. But the form not showing up in html table. Please check Commented Jul 23, 2014 at 3:25
  • OK I got it. I can't use form tag inside a table :( Commented Jul 23, 2014 at 3:43
  • Are you trying to create a form for each $product ? Commented Jul 23, 2014 at 3:44

1 Answer 1

1

change:

$html .= "<tr>
                <form method='POST' id='form-".$product->virtuemart_product_id."' class='product js-recalculate' action = '' >

become:

$html .= "<tr>
                <form method='POST' id='form-".$product->virtuemart_product_id."' class='product js-recalculate' action = '' >";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.