Forms
Save form-block HTML
/a/FormBlock_saveCode
Save non-empty block HTML, extracting embedded data-URI images into tenant file storage.
When to use this endpoint
Use this from the CRM2 Form Blocks editor. It currently has the same server implementation as FormBlock_setCode.
Authentication and permissions
The request must authenticate with signed API-key fields or a logged-in CRM session and is scoped to the authenticated tenant.
The handler performs no record-owner or page-permission check. Definition writes are blocked when the tenant’s features2.disableFormEdits flag is 1, except for the temporary setup user identified by userdata.meta.is_tmp=1.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | Positive integer | Yes | Existing tenant block ID. |
code | String | Yes | Non-empty HTML after trimming. Valid embedded data:image...;base64,... image sources are extracted and replaced with /f/... URLs. |
Example request
$result = FM_api('FormBlock_saveCode', [
'id' => '4821',
'code' => '<section><h2>Service summary</h2></section>',
]);
Example response
{
"ok": 1
}
Errors and unusual responses
| Response | Condition |
|---|---|
{"error":"not logged in"} | No authenticated tenant context is available. Invalid signed credentials can be rejected by the dispatcher before the handler runs. |
{"error":"invalid or missing parameter: id"} | ID is absent or not positive. |
{"error":"invalid or missing parameter: code"} | Code is absent or blank after trimming. |
{"error":"no such form block"} | The ID does not exist. |
{"error":"form edits are disabled for this account"} | Definition edits are disabled. |
Legacy application errors may be returned with HTTP 200. Check the decoded response for error, not only the HTTP status.
Behaviour and edge cases
- An unchanged normalized value returns
{"ok":1,"warning":"no change needed"}. - Embedded images larger than twice their requested HTML width and height are resampled to that doubled display size. Missing dimensions fall back to the source image size.
- Invalid or empty data-URI images are left as supplied. Removed or replaced extracted images are not garbage-collected by this endpoint.
Side effects
- Updates
codeand Unix-secondslast_edited. - May create type-
22file records and stored PNG objects underformblock_images/<id>/.
See it in Fieldmotion
CRM1
No production CRM1 caller was found; CRM1 uses FormBlock_setCode.
CRM2
Open Settings → Forms → Form Blocks, edit the Code tab, and save.
Related endpoints
FormBlock_setCodeis the established equivalent route.FormBlock_getreloads the stored HTML.