Data Variables
Core Forms supports two variable systems for inserting dynamic data into emails, redirects, form markup, and other contexts.
Bracket Variables: [field_name]
Used in email bodies, subjects, headers, and redirect URLs. Processed by cf_replace_data_variables() after form submission.
Field Variables
[field_name] Value of a specific submitted field
[all] All fields as "name: value" pairs, separated by <br />
[all:label] All fields with human-readable labels as "Label: value" pairs
System Variables
| Variable | Value |
|---|---|
[CF_FORM_ID] |
Form post ID |
[CF_FORM_TITLE] |
Form title |
[CF_TIMESTAMP] |
Submission timestamp (Y-m-d H:i:s) |
[CF_IP_ADDRESS] |
Submitter's IP address |
[CF_USER_AGENT] |
Browser user agent string |
[CF_REFERRER_URL] |
Page URL where form was submitted |
Payment Variables (4.1)
Available on submissions that went through a payment gateway. Empty string for free submissions.
| Variable | Value |
|---|---|
[CF_PAYMENT_STATUS] |
pending_payment / paid / payment_failed / refunded |
[CF_PAYMENT_PROVIDER] |
stripe / paypal / razorpay / polar |
[CF_PAYMENT_ID] |
Provider-issued payment id (Stripe session id, PayPal order id, etc.) |
[CF_PAYMENT_AMOUNT] |
Major-unit decimal, two places (19.99, or 1500 for JPY) |
[CF_PAYMENT_AMOUNT_FORMATTED] |
Currency code + amount (USD 19.99) |
[CF_PAYMENT_CURRENCY] |
ISO-4217 code (USD, EUR, INR, JPY) |
These variables are populated after the webhook confirms payment, so
they only resolve correctly inside actions that fire from
cf_form_success (which payment-required forms trigger from the webhook
handler, not from the initial submit). Use them for receipt emails:
Thanks for your order!
Order: [CF_PAYMENT_ID]
Total: [CF_PAYMENT_AMOUNT_FORMATTED]
How It Works
// Replace variables in a string using submission data
$result = cf_replace_data_variables( $string, $submission, $escape_function );
The third parameter controls escaping:
- 'strip_tags' -- Strip HTML (used for subjects, headers)
- 'esc_html' -- Escape HTML entities (used for HTML email bodies)
- null -- No escaping (used for plain text email bodies)
Example: Email Subject
New [inquiry_type] from [name] - [CF_FORM_TITLE]
Becomes:
New Sales Inquiry from Jane Smith - Contact Form
Example: Redirect URL
https://example.com/thank-you?name=[name]&ref=[CF_FORM_ID]
Example: Email Body
Hello,
You received a new submission from [name] ([email]).
Form: [CF_FORM_TITLE]
Submitted: [CF_TIMESTAMP]
IP: [CF_IP_ADDRESS]
--- All Fields ---
[all:label]
[all] vs [all:label]
[all] outputs field names as-is:
first_name: Jane
last_name: Smith
email: jane@example.com
[all:label] converts field names to labels:
First Name: Jane
Last Name: Smith
Email: jane@example.com
The label format converts underscores to spaces and capitalizes words.
Template Tags: {{tag.field}}
Used in form markup (HTML) for pre-filling fields and dynamic content. Processed by cf_template() before the form is rendered.
Built-in Tags
{{user.field}}
Access current WordPress user properties:
<input type="text" name="name" value="{{user.display_name}}" />
<input type="email" name="email" value="{{user.user_email}}" />
<input type="hidden" name="user_id" value="{{user.ID}}" />
Available properties: Any property on the WP_User object -- ID, user_email, display_name, user_login, first_name, last_name, etc.
{{post.field}}
Access the current post or page properties:
<input type="hidden" name="page_id" value="{{post.ID}}" />
<input type="hidden" name="page_title" value="{{post.post_title}}" />
Available properties: Any property on the WP_Post object -- ID, post_title, post_name, post_type, etc.
{{url_params.field}}
Access URL query parameters:
<!-- For URL: ?ref=newsletter&campaign=spring -->
<input type="hidden" name="referral" value="{{url_params.ref}}" />
<input type="hidden" name="campaign" value="{{url_params.campaign}}" />
Fallback Values
Use || to provide a fallback when a tag is empty:
<input type="text" name="name" value="{{user.display_name || Guest}}" />
Custom Template Tags
Register your own tags via the cf_template_tags filter:
add_filter( 'cf_template_tags', function( $tags ) {
// Simple scalar value
$tags['site'] = [
'name' => get_bloginfo( 'name' ),
'url' => home_url(),
'email' => get_option( 'admin_email' ),
];
// Callable that accepts a field parameter
$tags['company'] = function( $field ) {
$data = [
'name' => 'Acme Corp',
'phone' => '+1-555-0100',
'address' => '123 Main St',
];
return $data[ $field ] ?? '';
};
return $tags;
} );
// Usage: {{site.name}}, {{company.phone}}
Tag Syntax
{{ tag.field }} Basic replacement
{{ tag.field || fallback }} With fallback value
{{ tag }} Scalar value (no field)
Whitespace around {{ and }} is optional.
Where Each System Is Used
| Context | System | Function |
|---|---|---|
| Email subject | Bracket [var] |
cf_replace_data_variables() |
| Email message body | Bracket [var] |
cf_replace_data_variables() |
| Email headers | Bracket [var] |
cf_replace_data_variables() |
| Redirect URL | Bracket [var] |
cf_replace_data_variables() |
| Action settings | Bracket [var] |
cf_replace_data_variables() |
| Form HTML markup | Template {{tag}} |
cf_template() |
| Default field values | Template {{tag}} |
cf_template() |