If you must really use PDF forms due to formatting, graphics etc. your best bet is probably to create the PDF forms using good old Acrobat or another PDF authoring solution. Store the blank forms on your server.
Then install pdftk (http://www.accesspdf.com/pdftk/) on the server.
From there you have a couple of options... 1) require the end-user to download, fill out and upload the forms, or 2) create a web-based form with the required fields.
With option 1, you can use PDFTK to retrieve the form field data as it passes through the upload process, and store that in your DB. I use this solution for incoming PDF forms, something like this:
// capture $filename from upload....
$result = shell_exec("/usr/local/bin/pdftk $filename dump_data_fields");
$result = explode("\n",$result);
// parse out form fields, in "key: value" format from PDFTK
foreach ($result as $line) {
if (strpos($line,"FieldName")===0) {
$fieldname = substr($line,strpos($line,":")+2);
}
if (strpos($line,"FieldValue")===0) {
$fieldvalue = $this->decodePDFentities(substr($line,strpos($line,":")+2));
$fields[$fieldname] = $fieldvalue;
}
}
$fields = array("form"=>$fields);
function decodePDFentities($text) {
$text= html_entity_decode($text,ENT_QUOTES,"ISO-8859-1"); #NOTE: UTF-8 does not work!
$text= preg_replace('/&#(\d+);/me',"chr(\\1)",$text); #decimal notation
$text= preg_replace('/&#x([a-f0-9]+);/mei',"chr(0x\\1)",$text); #hex notation
$text= str_replace("\r","\n",$text); #clean up dumb carriage returns
return $text;
}
With option 2, you could store the web form data in your DB, update the PDF form fields, merge the pertinent PDF pages together and return the complete PDF to your user (probably a more elegant solution). I have read that pdftk may have some formatting problems when updating form fields but I haven't actually tried this. You would simply pipe stdout to the "pdftk fill-form - " option from your script -- of course you'd need the form fields in the right order!