I have successfully got checkbox data from html forms into a mysql db, but now i want to print off a form into pdf with the checkbox data...i have details how to make the form, including how to present comment boxes etc, but nothing on checkboxes, can anyone help? thanks in advance
getting a checkbox from php into pdf
Hi Charlie,
Gonna have to check I understand what's going on here ...
You said -'I have successfully got checkbox data from html forms into a mysql db, but now i want to print off a form into pdf with the checkbox data... i have details how to make the form, including how to present comment boxes etc, but nothing on checkboxes, can anyone help? thanks in advance'
Ok ... once the data is in the db we can pretty much forget where it came from and start from there, so the problem is - how do you get (any) data from mysql ... using php ... to display in a 'form-template' pdf.
Is that right? If so, show us the code you've already got that makes the form with the comment boxes etc. so we don't have to work too hard
Paul.
you can create 2 images (one checked, the other not) and use if statement to show the right one. If you want a real checkbox you can download the fpdf library and use the "Dynamic form with JavaScript class" of that lib.
thanks lads,
here is my code which takes the data from the db and puts it into an html doc, at the moment i am printing this form from within the browser, hence the reason why i want to print via pdf...
<td><input type="checkbox" name="engbx26" value="1"<?php if ($_REQUEST['engbx26']==1){echo "CHECKED disabled";} else {echo"disabled";}?>></td>
thanks for the idea of an image, i hadnt thought of that...if you need more code, let me know
Hi charliecharles,
I reckon the codes Paul is referring to, are your PHP codes to output to a PDF file.
Which PDF module are you using?
Basically, the easiest way to accomplish that is to write a custom function to draw a checkbox.
e.g.
function drawCheckbox($x, $y, $checked = 0)
{
// $x - the x-axis position
// $y - the y-axis position
// $checked - whether to check the box
// Start drawing checkbox
if ($checked==1)
{
// draw marked checkbox using PDF's line drawing functions
}
else
{
// draw empty checkbox using PDF's line drawing functions
}
}
Cheers.
ok, i am not that far ahead...i have played around with the pdf code in this book, 'PHP and MySQL Web Development, 2nd edition
Luke Welling, Laura Thomson', which is very good, but had no idea how to insert the checkbox...
i think you have all given me some good ideas, so i'll start to put it together...i'll be back though no doubt!
i am getting no where with the checkboxes...i am basically doing a str_replace into a rtf document now, as i had problems using pdf, each time i tried i was getting 'error in document'
here is the code
$box1=ImageCreateFromPNG('checked.PNG');
$box2=ImageCreateFromPNG('unchecked.PNG');
// replace the place holders in the template with our data
$output = str_replace( '<<NAME>>', $name, $output );
$output = str_replace( '<<box1>>',$box1, $output );
$output = str_replace( '<<box2>>', $box2, $output );
$output = str_replace( '<<mm/dd/yyyy>>', $date, $output );
// send the generated document to the browser
// or change all 1's to checked boxes, and all zero's to unchecked boxes
echo $output;
all i want to do is find bring all the checkboxes data from the database, a mix of 1's and 0's and then substitute the 1's for a checked image, and the 0's for an unchecked image...
thanks in advance