> ## Documentation Index
> Fetch the complete documentation index at: https://docs.carescale.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These guides connect a treatment facility's website forms to Carescale. Each facility has one website forms endpoint: an endpoint address and a secret, both copied from Carescale under Settings, Website forms.
> Send every submission as an HTTPS POST with a JSON body and the header Authorization: Bearer <secret>. Use the endpoint address exactly as Carescale shows it. Never put it behind a redirect or a proxy that redirects.
> Keep the secret out of committed code and out of client-side JavaScript. Put it in wp-config.php or a server-side environment setting.
> Gravity Forms Elite and Nonprofit licenses can use the Webhooks Add-On with no code. Basic and Pro licenses use the snippet. Any other form tool follows the payload contract on the Other form tools page.
> Never use real patient or client details in examples, logs or test submissions. Use made-up names, the 555 phone range and example.com addresses.
> Labels in bold match the Carescale app and Gravity Forms exactly. Quote them as written.

# Gravity Forms snippet

> Connect Gravity Forms to Carescale on any license with a short PHP file that sends each submission and its field labels.

The snippet works on every Gravity Forms license, Basic and Pro included. It sends each submission together with the form's field labels, so Carescale can match the fields with no manual setup.

On an Elite or Nonprofit license you can use the [Webhooks Add-On](/website-forms/gravity-forms-webhooks) instead, which needs no code and sends entries that are marked **Not Spam** later.

You need the **Endpoint address** and the secret from the facility's Carescale admin.

## 1. Add the endpoint to wp-config.php

Add these two lines to `wp-config.php`, above the line that reads `/* That's all, stop editing! */`. Use the facility's own values.

```php wp-config.php theme={null}
define( 'CARESCALE_FORMS_URL', 'https://your-endpoint-address-from-carescale' );
define( 'CARESCALE_FORMS_SECRET', 'wfs_your_secret_here' );
```

Keep the secret here, out of the theme and out of version control.

## 2. Add the snippet

Create the file `wp-content/mu-plugins/carescale-forms.php` with the content below. A must-use plugin loads on every request and can't be switched off by accident. If the `mu-plugins` folder doesn't exist, create it.

```php wp-content/mu-plugins/carescale-forms.php theme={null}
<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

add_action( 'gform_after_submission', 'carescale_send_inquiry', 10, 2 );

function carescale_send_inquiry( $entry, $form ) {
	if ( rgar( $entry, 'status' ) === 'spam' ) {
		return;
	}

	$fields = array();
	foreach ( $form['fields'] as $field ) {
		if ( in_array( $field->type, array( 'html', 'section', 'page', 'captcha', 'turnstile' ), true ) ) {
			continue;
		}

		$inputs = array();
		foreach ( is_array( $field->inputs ) ? $field->inputs : array() as $input ) {
			if ( rgar( $input, 'isHidden' ) ) {
				continue;
			}
			$inputs[] = array(
				'id'    => (string) rgar( $input, 'id' ),
				'label' => rgar( $input, 'customLabel' ) ? rgar( $input, 'customLabel' ) : rgar( $input, 'label' ),
			);
		}

		$choices = array();
		foreach ( is_array( $field->choices ) ? $field->choices : array() as $choice ) {
			$choices[] = array(
				'text'  => rgar( $choice, 'text' ),
				'value' => rgar( $choice, 'value' ),
			);
		}

		$fields[] = array(
			'id'      => (string) $field->id,
			'label'   => $field->label,
			'type'    => $field->type,
			'inputs'  => $inputs,
			'choices' => $choices,
		);
	}

	$response = wp_remote_post(
		CARESCALE_FORMS_URL,
		array(
			'timeout' => 10,
			'headers' => array(
				'Content-Type'  => 'application/json',
				'Authorization' => 'Bearer ' . CARESCALE_FORMS_SECRET,
			),
			'body'    => wp_json_encode(
				array(
					'entry' => $entry,
					'form'  => array(
						'id'     => (string) $form['id'],
						'title'  => $form['title'],
						'fields' => $fields,
					),
				)
			),
		)
	);

	if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) >= 300 ) {
		GFCommon::log_error( __FUNCTION__ . '(): Carescale delivery failed for entry #' . rgar( $entry, 'id' ) );
	}
}
```

What it does:

* It runs after each submission is saved, and **skips entries Gravity Forms flags as spam**.
* It sends the entry plus the form's title and fields: each field's label, type, visible inputs and choices. Layout fields and captchas are left out.
* It sends JSON with `Authorization: Bearer` and the secret, and waits up to 10 seconds.
* When the delivery fails, it writes an error to the Gravity Forms log. Logging is off by default, so turn it on only while you troubleshoot.

To send only one form, change `gform_after_submission` to `gform_after_submission_` followed by the form ID, for example `gform_after_submission_3`. For several forms, add one `add_action` line per form.

## Limits to know

* **No retry.** The snippet sends each entry once. If the site can't reach Carescale at that moment, the entry isn't sent. The Carescale card shows a refused delivery under **Last rejected delivery**. A delivery that never arrives shows nothing.
* **Not Spam entries are never sent.** An entry flagged as spam is skipped. Marking it **Not Spam** later doesn't run the snippet again, so enter that person as a lead by hand.
* **It runs in the visitor's request.** The visitor sees the confirmation once Carescale answers, which normally takes well under a second.
* **You maintain it.** Keep the file when the site moves hosts or themes.

## Test it

1. Submit the form on the live site with made-up details: a 555 phone number and an `example.com` email.
2. In Carescale, the card reads **Receiving**, the form appears in the forms list under its title, and a new lead is at New.
3. Clear the test lead with **Not an inquiry**.

Nothing arrived? See [Troubleshooting](/website-forms/troubleshooting).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.