How to integrate e-signatures into a PHP application

An e-signature integration lets your PHP service own the full signing loop instead of sending people out to another product. That keeps the workflow inside the app your users already know, and it removes the extra tabs and handoffs that usually slow the document signing process down.
In this blog post, we'll show you how to easily add e-signing into your own application using Formable. Formable offers a robust PHP SDK and detailed documentation to make the integration process as easy as possible.
What you'll need:
- PHP 8.1 or newer
- Composer
- A Formable account (paid or free sandbox)
- An API key from Formable account settings
Table of Contents
- Why an e-signature API from PHP?
- Step 1: installing the Formable PHP SDK
- Step 2: creating the client
- Step 3: create a template from your document
- Step 4: choose a signing flow
- Step 5: embed signing in Laravel
- Step 6: handle webhooks
- Step 7: download the signed PDF
- Error handling and test mode
- Conclusion
- FAQs
Why an e-signature API from PHP?
Say you write PHP for a property management platform. Each lease still needs to be signed by the tenant and the landlord. When that lives in email attachments and a shared drive, the latest file goes missing, nobody can tell who has signed, and move-in slips. By integrating with Formable, all those manual signing processes can be automated within the platform.
Step 1: installing the Formable PHP SDK
composer require formable/formable-sdk
Note:
For more details and advanced usage, you can also reference the Official Formable PHP SDK Documentation.
Step 2: creating the client
Create one client at startup. In Laravel, bind it once in a service provider so controllers do not keep constructing clients.
use Formable\Formable;
$formable = new Formable(getenv('FORMABLE_API_KEY'));
use Formable\Formable;
use Illuminate\Support\ServiceProvider;
class FormableServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(Formable::class, function () {
return new Formable(config('services.formable.key'));
});
}
}
The API key lives in .env, not in a Blade view.
Step 3: create a template from your document
A template is the re-usable document where you or your users place the fields for the signers to fill in.
Signer roles are optional for single signers. If you need to support multi-party signing, they are required as you need to specify which role needs to fill out which field.
$result = $formable->templates->create(
file: './lease.pdf',
filename: 'lease.pdf',
signerRoles: [
['name' => 'Tenant', 'order' => 0],
['name' => 'Landlord', 'order' => 1],
],
);
$templateId = $result['templateId'];
echo $result['editTemplateAccess']['editUrl'];
Open the edit URL, place at least one required signature field, assign it Tenant. The URL expires after a day:
$edit = $formable->templates->createEditUrl($templateId);
echo $edit['editUrl'];
Save $templateId and reuse it for later signature requests.
Step 4: choose a signing flow
You can choose to send a signing link via email to your user, or have your user sign within your own application within an iFrame.
If choosing email delivery, implement using the following code snippet.
$request = $formable->signatureRequests->create(
templateId: $templateId,
signers: [
['email' => 'jane@example.com', 'name' => 'Jane Doe', 'role' => 'Tenant'],
['email' => 'owner@yourco.com', 'name' => 'Alex Chen', 'role' => 'Landlord'],
],
testMode: true,
);
echo $request['signatureRequestId']; // save this
If you want your users to sign inside your application, the next section will show you how to implement the iframe path.
Step 5: embed signing in Laravel
Embedded signing requires two server calls.
First: Create the signature request.
Second: Mint a short-lived signing URL using the id from the signature request.
use Formable\Formable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::post('/api/signature-requests', function (Request $request, Formable $formable) {
$signer = $request->input('signer');
$result = $formable->signatureRequests->createEmbedded(
templateId: $request->input('templateId'),
signers: [[
'email' => $signer['email'],
'name' => $signer['name'],
'role' => 'Tenant',
]],
testMode: true,
);
return [
'signatureRequestId' => $result['signatureRequestId'],
'recipientSignatureId' => $result['signers'][0]['recipientSignatureId'],
];
});
Route::get('/api/signing-url', function (Request $request, Formable $formable) {
$signing = $formable->signatureRequests->createSigningUrl(
$request->query('recipientSignatureId')
);
return [
'signingUrl' => $signing['signingUrl'],
'expiresAt' => $signing['expiresAt'],
];
});
On the client, fetch the URL from your Laravel app and load it in an iframe. Formable posts onSigningComplete to the parent window:
const { signingUrl } = await fetch(
`/api/signing-url?recipientSignatureId=${recipientSignatureId}`
).then((res) => res.json());
document.getElementById("signing-frame").src = signingUrl;
window.addEventListener("message", (event) => {
if (event.origin !== "https://app.formabledocs.com") return;
if (event.data?.type === "onSigningComplete") {
// close the iframe or show a success state
}
});
<iframe
id="signing-frame"
width="100%"
height="800"
allow="fullscreen"
style="border: none;"
></iframe>
Step 6: handle webhooks
Register the path in Settings and keep the secret. HMAC is over the raw body. In Laravel, $request->getContent() is the right input. Do not json_encode($request->all()) and hash that.
use Formable\Formable;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
Route::post('/webhooks/formable', function (Request $request, Formable $formable) {
$rawBody = $request->getContent();
$received = $request->header('Content-Sha256', '');
$secret = base64_decode((string) config('services.formable.webhook_secret'), true);
$expected = base64_encode(hash_hmac('sha256', $rawBody, $secret, true));
if (!hash_equals($expected, $received)) {
abort(401, 'invalid signature');
}
$payload = json_decode($rawBody, true);
if (($payload['event']['event_type'] ?? null) === 'document_completed') {
$envelope = $formable->signatureRequests->getSignedEnvelope(
$payload['signing']['signature_request_id']
);
// download $envelope['signedEnvelopePresignedUrl'], store the PDF
}
return response('', 200);
});
document_completed is the terminal event. Once you receive this event, this means all parties have signed the document, and you may now fetch the signed document.
Alternatively, if you don't want to expose a webhook endpoint, you can poll for signature request status updates.
$current = $formable->signatureRequests->get($signatureRequestId);
if ($current['status'] === 'Completed') {
// safe to download
}
$recent = $formable->signatureRequests->list(
updatedSince: new DateTimeImmutable('-1 day')
);
Step 7: download the signed PDF
The signed envelope URL is a short-lived presigned link.
$envelope = $formable->signatureRequests->getSignedEnvelope($signatureRequestId);
$pdf = file_get_contents($envelope['signedEnvelopePresignedUrl']);
The signed envelope includes the Formable audit trail of all relevant events.
Error handling and test mode
Non-2xx responses throw a FormableError. A 409 from getSignedEnvelope means the document is not finished:
use Formable\FormableError;
try {
$formable->signatureRequests->getSignedEnvelope($signatureRequestId);
} catch (FormableError $error) {
if ($error->status === 409) {
// wait for document_completed
return;
}
throw $error;
}
400 is usually a fieldId that is not on the template. 401 is the API key. 404 is an unknown id.
Set testMode: true while you integrate. Test documents are watermarked, not legally binding, and do not count toward billing. Clear the flag for production.
Conclusion
Your PHP service now owns signing end to end: a reusable template, email or embedded signing, a verified webhook, and a signed PDF with an audit trail stored on your side. The same routes work whether the document is finance, HR, real estate, or anything else your app already creates.
To learn more about the Formable API, take a look at our API documentation. We support SDKs for a wide variety of languages, and are always looking to support more in the near future.
If you have questions, email matt@formabledocs.com. We are always happy to assist you!
FAQs
How do I add e-signatures to a PHP application?
Install formable/formable-sdk, create a template from your PDF or DOCX, then create a signature request. Formable can email signers, or you can generate a signing URL and embed it in an iframe. A webhook tells you when to download the signed PDF.
Does the SDK depend on a web framework?
No. The client is a plain class. The examples use Laravel. Symfony, WordPress plugin code, or a single index.php can call the same methods. Read $request->getContent() on the webhook route before you parse JSON.
How do I know when a document has been signed?
Handle document_completed on your webhook, or poll get until status is Completed.
Can I test without sending legally binding documents?
Yes. Set testMode: true on signature requests. Test documents are watermarked, not legally binding, and do not count toward billing.
Does the signed PDF include an audit trail?
Yes. Every signed document includes an appended audit trail with created, sent, signed, and completed events, including timestamps, actors, and IP addresses, which supports enforceability under ESIGN and UETA.




