Complex rules, built by clicking.

kConditionsEditor takes over a <textarea> and puts a nested condition builder in its place. Every change writes portable JSON straight back into the textarea, so your form posts exactly as it always did — and the evaluator SDKs turn that JSON into a boolean anywhere else in your stack.

No dependencies No build step ~30 KB of JS JS + PHP SDKs MIT

Open the playground Read the docs

Try it

This is a contact-form rule. Press Edit Conditions, build something, and watch the JSON and the live evaluation below react. View source is switched on here, so you can also see the generated SQL.

Swap the look without losing the rule — or see all five on the Skins page.

—

JSON written to the textarea

—

Or write SQL straight into the field

Same editor, output: 'sql'. This one is pointed at a textarea that already accepts SQL — the case where you want to give people who do not write SQL a friendlier way to fill in a field they could otherwise only type into. The field is left visible on purpose, so they can see what is being written for them.

documentInComment: true tucks the rule into a trailing comment, so this one field round-trips: reload the page, and the builder reads its own state back out of the SQL. Change the dialect to watch it regenerate.

This is safe precisely because the field already took SQL — the trust boundary has not moved. If your endpoint currently receives JSON, keep posting the document and build the SQL on the server instead. Both are first-class; the docs spell out which is which.

How it fits together

1. The browser writes it

The editor knows your fields, which operators each one accepts, and which fields may be compared against which. It emits a document that describes the rule and nothing else — no functions, no closures.

2. Anything reads it

Pass the document and a flat set of field values to an SDK and get true or false back. The JS and PHP SDKs run the same 34 conformance fixtures, so they agree by construction.

Quick start

<link rel="stylesheet" href="src/k-conditions-editor.css">
<textarea id="conditions" name="conditions"></textarea>

<script src="src/k-conditions-evaluator.js"></script>
<script src="src/k-conditions-editor.js"></script>
<script>
  KConditionsEditor.attach('#conditions', {
    emptyText: 'Always',
    fields: [
      { name: 'name',  label: 'Name',          type: 'text' },
      { name: 'dob',   label: 'Date of Birth', type: 'date' },
      { name: 'state', label: 'State',         type: 'enum',
        choices: ['Florida', 'Texas', 'California'] }
    ]
  });
</script>

Then, on the server:

use function Kastrack\ConditionsEditor\evaluate;

if (evaluate($_POST['conditions'], $submission)) {
    // do the thing
}

The bits that usually hurt

Server-only conditions, checked early where possible

"Is this email already registered?" can only be answered on the server. Mark the operator availableIn: ["server"] with a client: "skip" policy, and the same rule pre-checks everything else in the browser without ever blocking the submit — then evaluates in full on the server.

Skipping means skipping

A skipped condition behaves as though it were never in the document. Its siblings decide the group; a group left with no children drops out of its own parent. A skipped condition can never turn an OR true on its own.

Field-to-field comparisons, but only the sensible ones

Any value slot can point at another field instead of a literal. comparableWith narrows that list per field — by name, by type:, by group:, or false to switch it off.

One hook instead of a boolean

Pass a function as the last argument to any SDK entry point and it receives the original arguments plus the result and the details, and its return value becomes the return value. Useful for logging what got deferred.