Execute Custom php Code: Frequently Asked Questions
Arclab® Web Form Builder
question_answer Execute Custom PHP Code F.A.Q. Index
comment How to use a dynamic Attachment File Name
The file name set in the dialog can be overwritten using the php variable $att_file_name.
Samples:
$att_file_name = "abc.pdf";
$att_file_name = "$ID23.pdf"
comment How to access the PNG Image of a Signature Field
The base64 encoded png image is stored in the variable $IDxx_b64,
e.g. $ID21_b64
(you can get the IDxx
when you click on the signature field in the form).
Use:
// base 64 encoded image
bytes
$IDxx_b64
// image as data url
$dataurl = 'data:image/png;base64,'.$IDxx_b64;
// image bytes (image data stream)
$bytes = base64_decode($IDxx_b64);
If you want to add the signature to a pdf file created using TCPDF use e.g.
// insert the image
$pdf->Image('@'.base64_decode($IDxx_b64),10,10);
// the '@' character is used to indicate
that the 1st parameter contains an image data stream and not an image file
name
// 10,10 is x and y
// for further details and parametes look
at the TCPDF:Image user manual
// if the signature is
optional (NOT a required field) use:
if($IDxx_b64)
$pdf->Image('@'.base64_decode($IDxx_b64),10,10);
If you want to add the signature to a pdf file created using FPDF use e.g.
$dataurl = 'data:image/png;base64,'.$IDxx_b64;
$pdf->Image($dataurl,10,10,0,0,'PNG');
// 10,10 is x and y
//
0,0 for auto size
// specify the
image type PNG
// if the signature is
optional (NOT a required field) use:
if($IDxx_b64)
{
$dataurl = 'data:image/png;base64,'.$IDxx_b64;
$pdf->Image($dataurl,10,10,0,0,'PNG');
}
comment Sample: Add PNG Image of Signature Field to PDF using TCPDF
The base64 encoded png image is stored in the variable $IDxx_b64,
e.g. $ID21_b64
(you can get the IDxx
when you click on the signature field in the form).
TCPDF Image Sample:
...
$html = '<p>...</p>';
// add HTML content
$pdf->writeHTMLCell(0, 0, 10, 10, $html);
// insert image
if($IDxx_b64)
$pdf->Image('@'.base64_decode($IDxx_b64),10,10);
// 10,10 is x and y (by default in mm) from the upper left corner
// for further details and parametes look at the TCPDF:Image user manual
// add the image function before outputting
the PDF !
$att_content_data = $pdf->Output('ignored', 'S');
comment Sample: Add PNG Image of Signature Field to PDF using FPDF
The base64 encoded png image is stored in the variable $IDxx_b64,
e.g. $ID21_b64
(you can get the IDxx
when you click on the signature field in the form).
FPDF Image Sample:
...
// add some text
$pdf->Cell(0,10,'Hello World');
if($IDxx_b64)
{
$dataurl = 'data:image/png;base64,'.$IDxx_b64;
$pdf->Image($dataurl,10,10,0,0,'PNG');
}
// 10,10
is x and y from the upper left corner
// use 0,0 for auto size (width
and height)
// add the image function
before outputting the PDF !
$att_content_data = $pdf->Output('S');
comment How to access the Uploaded Files of a "File Upload" Form Element ($_FILES array)
Files uploaded using a "File Upload" form element are attached
to the email as an attachment by default. No custom PHP code is required
for file attachments.
However, if you need direct access to
the temporary files on the server, you can access them using the $_FILES['IDxx']
array.
(you can get the IDxx when
you click on the file upload field in the form)
Example for file upload with only 1 file:
if ($_FILES['IDxx']['name'][0]!="")
{
// temporary path/filename "tmp_name" of the
uploaded file on the server
// please note that "tmp_name"
is a generic file name, which does not match the original file name!
$tempfilename=$_FILES['IDxx']['tmp_name'][0]
// file "name" of the uploaded file
$filename=$_FILES['IDxx']['name'][0];
// file "type"
$filetype=$_FILES['IDxx']['type'][0];
// file "size" in bytes
$filesize=$_FILES['IDxx']['size'][0];
// file content (binary data)
// $filebytes=file_get_contents($tempfilename);
}
Example for file upload with multiple files:
// enumerate uploaded files
for IDxx
foreach($_FILES['IDxx']['tmp_name'] as $i => $tempfilename)
{
// temporary path/filename
"tmp_name" of the uploaded file on the server
//
$tempfilename contains the temp filename (path) of the
uploaded file
// please note that "tmp_name" is a
generic file name, which does not match the original file name!
// file "name" of the
uploaded file
$filename=$_FILES['IDxx']['name'][$i];
// file "type"
$filetype=$_FILES['IDxx']['type'][$i];
// file "size" in bytes
$filesize=$_FILES['IDxx']['size'][$i];
// file content (binary data)
// $filebytes=file_get_contents($tempfilename);
}
Please contact us if you cannot find an answer to your question in the F.A.Q. or user manual.