Guides · PHP · cURL extension
Wait for a JavaScript-rendered form, then make it fillable in PHP with cURL extension
React, Vue and friends render forms after the initial HTML arrives — so a too-eager render captures a spinner where the form should be, and a pdf_forms pass finds zero controls to convert. The fix is two request parameters, no code changes on your site: "wait_until": "networkidle" holds the render until the page stops fetching, and delay adds a fixed settling pause after that.
Below is a complete, runnable PHP program using cURL extension, no third-party dependency needed. It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.
<?php
$body = json_encode([
'url' => "https://your-app.com/apply",
'format' => "pdf",
'pdf_forms' => true,
'wait_until' => "networkidle",
'delay' => 500,
]);
$ch = curl_init("https://snapdok.io/v1/render");
$headers = [];
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 90,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SNAPDOK_KEY'),
'Content-Type: application/json',
],
CURLOPT_HEADERFUNCTION => function ($ch, $line) use (&$headers) {
$parts = explode(':', $line, 2);
if (count($parts) === 2) $headers[strtolower(trim($parts[0]))] = trim($parts[1]);
return strlen($line);
},
]);
$bytes = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status !== 200) {
throw new RuntimeException("snapdok error $status: $bytes");
}
file_put_contents('spa-form.pdf', $bytes);
echo ($headers['x-form-fields'] ?? '?') . " // 0 here usually means you rendered too early\n";
wait_until accepts four stages, in order of patience: commit (bytes started arriving), domcontentloaded, load (the default), and networkidle (no network requests for a quiet period — the right choice for SPAs that hydrate after load). delay is an extra wait in milliseconds after that stage is reached: use a few hundred ms for forms that animate in, or that fetch their field list from an API after mount.
The feedback loop is X-Form-Fields: if it comes back 0 on a page you know has a form, the form was not in the DOM yet (or it is inside an iframe, which is never converted). Bump delay, or check the form is rendered server-side. Raise timeout (navigation cap, ms) for genuinely slow apps rather than looping retries — a failed render is never charged, but it is slower than one patient render.
Notes for cURL extension
Plain ext-curl, no Composer needed. The details that bite: CURLOPT_RETURNTRANSFER must be set or the bytes are echoed to stdout instead of returned; the HTTP status has to be read explicitly with curl_getinfo() because cURL happily "succeeds" on a 401; and response headers need a CURLOPT_HEADERFUNCTION callback if you want to check things like X-Form-Fields. file_put_contents is binary-safe in PHP — strings are byte arrays — so no "b" flag dance is needed.
Response headers worth reading
| Header | Meaning |
|---|---|
X-Form-Fields | 0 on a form page = rendered before the form existed. |
X-Demo-Duration-Ms | How long the render took (demo route). |
X-Cache | Cached responses replay instantly. |
Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.
Related guides
Same task, other stacks
- Wait for a JavaScript-rendered form, then make it fillable in Python with requests
- Wait for a JavaScript-rendered form, then make it fillable in Node.js with built-in fetch
- Wait for a JavaScript-rendered form, then make it fillable in Ruby with Net::HTTP
More with PHP + cURL extension
- Convert an HTML form to a fillable PDF
- Get a fillable PDF of just the form — no nav, no footer
- Generate a fillable invoice PDF from a web page
- Turn an online registration form into a fillable PDF
- Verify a fillable PDF render without opening the file
- Convert a URL to PDF
- Take a full-page screenshot
- Capture very tall pages as numbered tiles
- Take a retina-quality (2x) screenshot
- Take a JPEG screenshot at a custom viewport size
- Use the 24-hour render cache to cut costs
- Take a screenshot of a URL
- Capture a JavaScript-heavy page after it settles
- Wait for a specific element before capturing
- Add page numbers and headers to a PDF