任何人都可以帮助我如何阅读复选框中的值,以PDF格式显示它。我有一个名称,年龄,偏好等表格。我有一个偏好的复选框。当用户点击提交输入或选择的值以显示在pdf中时,我只有复选框的问题。它读取表单中的单个值。它从复选框中读取多个值。请帮助我,因为我是tcpdf的新手。这是我的代码。此代码仅从复选框中读取最后选择的值。请帮帮我。
php code
<script type="text/javascript">
$(function() {
$("#Submit").click(function(){
$('input[name=per]').click(function(){
$('input[name=per]').removeAttr('checked');
$(this).attr('checked', true);
});
document.getElementById("Form").submit();
});
</script>
<form name="Form" id="Form" method="POST" action="pdf/pdf.php">
<input type="checkbox" name="per" value="bike">bike<br/>
<input type="checkbox" name="per" value="car">Car<br/>
<input type="checkbox" name="per" value="bus">bus<br/>
<input type="hidden" name="formType" id="formType" value="veh" />
<input type="button" name="Submit" id="Submit" value="Submit" class="formButton" />
</div>
</form></div>
pdf code
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('S');
$pdf->SetTitle('S');
$pdf->SetSubject('S');
$pdf->SetKeywords('S');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$per="";
if($_REQUEST["formType"] == "veh") {
foreach($_POST['per'] as $check) {
echo $check;
}
}
$username = "root";
$password = "";
$hostname = "localhost";
$db = "mun";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($db,$dbhandle) or die('cannot select db');
mysql_query("INSERT INTO sjbhsmun1 (Name, age, grade, city, email,mobile, cper, choice1,choice2,choice3)
VALUES('$Name','$age','$per') ") or die(mysql_error());
----------------
--------
<tr>
<td width="40%" style="border: 1px solid #ccc;">Preferences</td>
<td width="60%" style="border: 1px solid #ccc;">';
$html .= $per;
</tr>
答案 0 :(得分:0)
将您的复选框名称从per
更改为per[]
<input type="checkbox" name="per[]" value="bike">bike<br/>
<input type="checkbox" name="per[]" value="car">Car<br/>
<input type="checkbox" name="per[]" value="bus">bus<br/>
在您的PDF代码中使用此代码获取所有值
if(isset($_POST['per'])){
foreach($_POST['per'] as $check) {
echo $check;
}
}
这将显示所有选中的框
答案 1 :(得分:0)
<input type="button" name="Submit" id="Submit" value="Submit" class="formButton" />
将此行更改为此
<input type="submit" name="Submit" id="Submit" value="Submit" class="formButton" />
尝试此代码
if(isset($_POST['per'])){
foreach($_POST['per'] as $check) {
echo $check;
}
}
也是Pooshonk提到的
<input type="checkbox" name="per[]" value="bike">bike<br/>
<input type="checkbox" name="per[]" value="car">Car<br/>
<input type="checkbox" name="per[]" value="bus">bus<br/>