Webforms API
Form loading
Before using the methods of the amo_forms_params
object, you need to ensure that the form has been successfully loaded and that the methods are available. This can be done using the amo_forms_loaded
method, which accepts a callback function that is executed once the form is initialized.
If the form ID is passed as the second argument, the callback will only be executed for the specific form, which is useful if multiple forms are placed on the page. The callback function receives an object with a form_id
property, allowing you to identify which form has been loaded.
Parameter | Type | Description |
---|---|---|
callback | function | Callback function |
id (optional) | string | Numeric ID of the form |
amo_forms_loaded(function (params) {
console.log(params);
if (params.form_id === 123456) {
amo_forms_params.resizeForm('amoforms_iframe_123456');
}
});
Form methods
In order to interact with forms placed on the page, there is a global object amo_forms_params
, which has the following methods available:
Forced form resize
Method amo_forms_params.resizeForm(id)
will recalculate the form's height based on the height of its contents. This is useful if the iframe is hidden when the page loads (for example, in a modal window), preventing its height from being calculated. Manually calling this method when the modal window opens will repaint the form.
Parameter | Type | Description |
---|---|---|
id | string | Form element ID |
amo_forms_params.resizeForm('amoforms_iframe_123456');
Subscribe to form submission
The amo_forms_params.onFormSubmit(callback, id)
method adds a callback for form submission. It accepts a second optional argument, the form id. If omitted, the callback will be triggered when any amoCRM form on the page is submitted (there may be multiple forms).
The callback accepts an object with form_id
and status
properties as an argument. The former contains the numeric form ID, while the latter can be success
or fail
, respectively, in case of successful submission or an error.
Parameter | Type | Description |
---|---|---|
callback | function | Callback function |
id (optional) | int | Numeric ID of the form |
amo_forms_params.onFormSubmit(function (params) {
console.log(params); // { form_id: 1234, status: 'success' }
}, 123456);
Updated about 12 hours ago