-
Notifications
You must be signed in to change notification settings - Fork 6
Embed Form
Philipp edited this page Oct 30, 2020
·
1 revision
Embedding Zammad native form is quite similar to embedding a chat. However there are some differences you need to take care of:
- Zammad currently only supports one single form without custom fields. But since version 0.8.0 Zammad WP has a neat alternative!
- An element in the DOM is required. It is either the modal trigger, or the form loads within that. This is described in more detail below.
Please use the zammad_register_form() function to add a form. First parameter defines the target DOM element, second allows overwriting default options.
add_action('init', function () {
if (function_exists('zammad_register_form')) {
zammad_register_form('#feedback-form');
}
});
As mentioned before you can either open the form in a modal or directly embed it into an element. If you want to embed it, set the modal option to false;
Below an example how you could embed a DOM element via WordPress action into the footer:
add_action('wp_footer', function () {
// This is an example trigger button (modal: true)
echo '<button id="feedback-form">Open Feedback Modal</div>';
// This is an example container div the form is embedded in (modal: false)
echo '<div id="feedback-form"></div>';
});
You can change the default options of Zammad Form via zammad_wp:form:defaults filter.
add_filter('zammad_wp:form:defaults', function ($defaults) {
return wp_parse_args(
[
'debug' => true,
'title' => __('Talk to us!', 'text-domain')
],
$defaults
);
});
| Options | Default | Type | Description |
|---|---|---|---|
| formElement | '#feedback-form' |
String |
DOM Element the form is attached to |
| debug | false |
Boolean |
Enable debugging for implementation. |
| modal | true |
Boolean |
Start modal dialog for form. |
| showTitle | true |
Boolean |
Show title in form. |
| messageTitle | 'Feedback Form' |
String |
Form Title |
| messageSubmit | 'Submit' |
String |
Submit Button label |
| messageThankYou | 'Thank you for your inquiry (#%s)! We\'ll contact you as soon as possible.' |
Boolean |
Thank you message after form submit. |
| attachmentSupport | false |
Boolean |
Add attachment option to upload. |