[英]TCPDF won't recognize $_POST
我正在嘗試創建一個通過POST接收數據的pdf,我知道正在接收數據,因為我使用“ var_dump($ _ POST)”進行了測試。
結果:
array (size=9)
'orcCar' => string 'S' (length=1)
'contItem' =>
array (size=1)
0 => string '1' (length=1)
'codProduto' =>
array (size=1)
0 => string '000zxxxxxxx' (length=14)
'qtdProduto' =>
array (size=1)
0 => string '20' (length=2)
'prcuProduto' =>
array (size=1)
0 => string '4.28' (length=4)
'prctProduto' =>
array (size=1)
0 => string '85.60' (length=5)
'descProduto' =>
array (size=1)
0 => string 'sdsudhudud' (length=33)
'countNitens' => string '2' (length=1)
'codClientecopia' => string '' (length=0)
但是,當我嘗試在html代碼中間或循環中使用它時,它將無法正常工作。
這是代碼的一部分:
for($i=0; $i < count($_POST["codProduto"]); $i++)
{
if ($_POST["prcuProduto"][$i]=="")
{
$_POST["prcuProduto"][$i] = '0';
}
$contador=$_POST["contItem"][$i];
// Set some content to print
$html.="<tr>
<td style='width:5%;'><input type='number' name='contItem[]'
style='width:100%'id='contItem' readonly='readonly' value=".$contador."
maxlength='5'></td>
<td style='width:20%;'><input type='text' name='codProduto[]'
style='width:100%'id='codProduto' readonly='readonly' maxlength='20'
value=". $_POST['codProduto'][$i]."></td>";
}
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);`enter code here`
由於以下原因,它不會進入循環
計數($ _ POST [ “codProduto”])
當使用值進行更改時,它可以工作,但是它仍然不會顯示任何值或“ td”。我也嘗試使用帖子中的值創建變量,但仍然無法工作。
有人可以幫我如何使用從tcpdf中獲取的絲絨嗎?
我重新創建了您的POST
對象,它對我來說很好地進入了循環。 這里有幾件事要注意。
首先, input
不是TCPDF HTML解析器支持的標記。 如果您只是想在字段值周圍添加框,請在td中添加邊框。
其次,TCPDF的HTML解析器非常脆弱。 您需要確保包含所有必要的HTML標記。 例如,在您的代碼中, $html
的內容未包裝在table
標簽中,並且行中沒有</tr>
標簽。 TCPDF還需要將所有HTML屬性都用雙引號引起來 。
在我使用TCPDF 6.2.17進行的測試中,以下代碼段有效:
$html = '<table cellpadding="2">';
//I'm adding a border on the cells, and TCPDF doesn't support CSS padding
//so we'll use table's cellpadding attribute. Not strictly required, but
//I thought it looked nice.
for($i=0; $i < count($_POST["codProduto"]); $i++)
{
if ($_POST["prcuProduto"][$i]=="")
{
$_POST["prcuProduto"][$i] = '0';
}
$contador=$_POST["contItem"][$i];
// Set some content to print
$html.="<tr>
<td style=\"width:5%; border: 1px solid black; \">$contador</td>
<td style=\"width:20%; border: 1px solid black; \">{$_POST['codProduto'][$i]}</td></tr>";
//Make sure we have our ending </tr> tag and wrap the style attributes in double
//quotes so TCPDF will actually pay attention to them.
}
$html .= '</table>';
// End our table and print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.