我无法在函数的php循环中创建HTML表单。我在这里做了什么:
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;
但这种形式没有出现&amp;在结束之前插入结束标记。它是这样的:
<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>
我错在哪里?
对于我想要做的更具体的输出,输出将是这样的:
<table>
loop start
<form action='' id='id='form-".$data."'>
<tr>
<td></td>
</tr>
</form>
loop end
</table>
但输出显示不正确。
答案 0 :(得分:1)
变化:
$html .= "<tr>
<form method='POST' id='form-".$product->virtuemart_product_id."' class='product js-recalculate' action = '' >
成为:
$html .= "<tr>
<form method='POST' id='form-".$product->virtuemart_product_id."' class='product js-recalculate' action = '' >";