简体   繁体   English

TCPDF无法识别$ _POST

[英]TCPDF won't recognize $_POST

I'm trying to create a pdf that receives data via POST,I know that the data is being received because i tested using "var_dump($_POST)". 我正在尝试创建一个通过POST接收数据的pdf,我知道正在接收数据,因为我使用“ var_dump($ _ POST)”进行了测试。

Result: 结果:

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)

But when i try to use it in the middle of the html code or in a loop it wont work. 但是,当我尝试在html代码中间或循环中使用它时,它将无法正常工作。

This is part of the code: 这是代码的一部分:

  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`

It won't enter the loop because of 由于以下原因,它不会进入循环

count($_POST["codProduto"]) 计数($ _ POST [ “codProduto”])

when changed with value it works, but it still won't show any values or the "td".I also tried creating variables with the values from the post but it still didin't work. 当使用值进行更改时,它可以工作,但是它仍然不会显示任何值或“ td”。我也尝试使用帖子中的值创建变量,但仍然无法工作。

Could someone help me how to use velues recived from post in tcpdf? 有人可以帮我如何使用从tcpdf中获取的丝绒吗?

I recreated your POST object and it enters the loop just fine for me. 我重新创建了您的POST对象,它对我来说很好地进入了循环。 There's a couple of things to note here. 这里有几件事要注意。

First, input is not a supported tag for the TCPDF HTML parser. 首先, input不是TCPDF HTML解析器支持的标记。 If you're just wanting to add boxes around the field values, then add a border to the td instead. 如果您只是想在字段值周围添加框,请在td中添加边框。

Secondly, TCPDF's HTML parser is pretty fragile. 其次,TCPDF的HTML解析器非常脆弱。 You need to make sure you include all the necessary HTML tags. 您需要确保包含所有必要的HTML标记。 For example, in your code the contents of $html are not wrapped in a table tag, and there's no </tr> tag for the rows. 例如,在您的代码中, $html的内容未包装在table标签中,并且行中没有</tr>标签。 TCPDF also needs all HTML attributes to be wrapped in double quotes . TCPDF还需要将所有HTML属性都用双引号引起来

In my tests with TCPDF 6.2.17, the following snippet works: 在我使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM