Hi Community,
I’m having trouble with dynamically prefilled custom fields in the Zendesk web widget. Despite following the documentation, the fields remain empty in the API request and do not appear in the created ticket.
Steps I’ve taken:
- Created custom fields in the Zendesk Admin settings. The fields are configured as "Customer can edit."
-
Used the following script to prefill fields dynamically using PHP variables:
html
Code kopieren
<script type="text/javascript"> window.zESettings = { webWidget: { color: { theme: '#9D7BFF', launcherText: '#FFF' }, contactForm: { fields: [ { id: 'name', prefill: { '*': '<?php echo $name; ?>' } }, { id: 'email', prefill: { '*': '<?php echo $email; ?>' } }, { id: 15119319576476, prefill: { '*': '<?php echo $goal; ?>' } } ] } } }; </script> <script id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key=<?php echo $_ENV["ZENDESC_KEY"]?>"> </script> -
Tested the setup. The widget appears correctly, but the dynamically prefilled values are not transmitted. For example:
-
nameandemaildo not appear anywhere in the ticket. - The custom field with ID
15119319576476is shown in the API request but has anullvalue.
-
The issue:
The generated API request looks like this:
json
Code kopieren
{
"request": {
"url": "https://MY_DOMAIN_BY_ZENDESK/api/v2/requests/104336.json",
"id": 104336,
"status": "new",
"priority": null,
"type": null,
"subject": "test",
"description": "test\n\n------------------\n",
"organization_id": null,
"via": {
"channel": "web",
"source": {
"from": {},
"to": {},
"rel": "web_widget"
}
},
"custom_fields": [
{ "id": 15119319576476, "value": null }
],
"fields": [
{ "id": 15119319576476, "value": null }
]
}
}
My question:
- Are there known limitations with dynamically prefilling fields in the web widget?
- Do we need to handle dynamic variables differently to ensure they are transmitted properly to Zendesk tickets?
- Has anyone successfully implemented dynamic prefill for custom fields in the web widget?
Any help or insight would be greatly appreciated. Thank you in advance!