Send form submissions to Formclick from Ionic and Capacitor apps, using Angular, React or Vue.
It has the same API as @formclick/react-native and the formclick Flutter package: a one-shot submitToFormclick() function and a small createFormclick() store that tracks loading, success and error state. There are no dependencies and no native plugin code.
| Web | iOS (Capacitor) | Android (Capacitor) |
|---|---|---|
| ✅ | ✅ | ✅ |
npm install @formclick/ionicGet your access key from the Formclick dashboard. Every example below uses YOUR_ACCESS_KEY.
Wrap the store in a service and expose its state as a signal:
// formclick.service.ts
import { Injectable, signal } from '@angular/core';
import { createFormclick, FormclickState, FormValues } from '@formclick/ionic';
@Injectable({ providedIn: 'root' })
export class FormclickService {
private store = createFormclick();
readonly state = signal<FormclickState>(this.store.getState());
constructor() {
this.store.subscribe((s) => this.state.set(s));
}
submit(data: FormValues) {
return this.store.submit({ formId: 'YOUR_ACCESS_KEY', data });
}
}<!-- contact.page.html -->
<form (ngSubmit)="send()">
<ion-input label="Name" [(ngModel)]="name" name="name" required></ion-input>
<ion-input label="Email" type="email" [(ngModel)]="email" name="email" required></ion-input>
<ion-button type="submit" [disabled]="formclick.state().loading">Send</ion-button>
@if (formclick.state().success) { <ion-text color="success">Sent!</ion-text> }
@if (formclick.state().error; as e) { <ion-text color="danger">{{ e.message }}</ion-text> }
</form>// contact.page.ts
send() {
this.formclick.submit({ name: this.name, email: this.email }).catch(() => {});
}import { useMemo, useSyncExternalStore } from 'react';
import { IonButton, IonInput, IonText } from '@ionic/react';
import { createFormclick } from '@formclick/ionic';
export function ContactForm() {
const form = useMemo(() => createFormclick(), []);
const { loading, success, error } = useSyncExternalStore(form.subscribe, form.getState);
async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
const fd = new FormData(e.currentTarget);
await form
.submit({ formId: 'YOUR_ACCESS_KEY', data: { name: String(fd.get('name')), email: String(fd.get('email')) } })
.catch(() => {});
}
return (
<form onSubmit={onSubmit}>
<IonInput label="Name" name="name" required />
<IonInput label="Email" name="email" type="email" required />
<IonButton type="submit" disabled={loading}>Send</IonButton>
{success && <IonText color="success">Sent!</IonText>}
{error && <IonText color="danger">{error.message}</IonText>}
</form>
);
}<script setup lang="ts">
import { onUnmounted, ref } from 'vue';
import { IonButton, IonInput, IonText } from '@ionic/vue';
import { createFormclick } from '@formclick/ionic';
const form = createFormclick();
const state = ref(form.getState());
onUnmounted(form.subscribe((s) => (state.value = s)));
const name = ref('');
const email = ref('');
function send() {
form.submit({ formId: 'YOUR_ACCESS_KEY', data: { name: name.value, email: email.value } }).catch(() => {});
}
</script>
<template>
<form @submit.prevent="send">
<ion-input label="Name" v-model="name" required />
<ion-input label="Email" type="email" v-model="email" required />
<ion-button type="submit" :disabled="state.loading">Send</ion-button>
<ion-text v-if="state.success" color="success">Sent!</ion-text>
<ion-text v-if="state.error" color="danger">{{ state.error.message }}</ion-text>
</form>
</template>import { submitToFormclick } from '@formclick/ionic';
const result = await submitToFormclick({
formId: 'YOUR_ACCESS_KEY',
data: { name: 'John', email: 'john@example.com' },
});
console.log(result.success, result.message);The default fetch works in Capacitor's web view. If you'd rather send requests through the native layer, pass your own fetch. For example, enable CapacitorHttp in capacitor.config.ts, which patches the global fetch:
plugins: { CapacitorHttp: { enabled: true } }Or pass any fetch-compatible function:
createFormclick({ fetch: myNativeFetch });| Config | Type | Default | Description |
|---|---|---|---|
submitBaseUrl |
string |
https://api.formclick.io/submit |
Base URL of the submissions API |
headers |
Record<string, string> |
none | Extra headers for every request |
fetch |
typeof fetch |
global fetch |
Custom fetch implementation |
onSuccess |
(result, options) => void |
none | Called after every successful submission |
onError |
(error, options) => void |
none | Called after every failed submission |
| Store member | Description |
|---|---|
submit(options) |
Sends a submission. Resolves with SubmitResult, rejects on error |
reset() |
Resets state to idle |
getState() |
Returns { loading, success, error, data } |
subscribe(listener) |
Calls listener on every change. Returns an unsubscribe function |
| Property | Type | Description |
|---|---|---|
formId |
string |
Your Formclick access key |
data |
FormValues |
Field values to submit |
submitUrl |
string? |
Overrides the full endpoint URL |
pnpm install
pnpm typecheck
pnpm build
pnpm test # runs against a local mock server, no network callsMIT © Formclick