zapier-platform icon indicating copy to clipboard operation
zapier-platform copied to clipboard

Custom Form Validation

Open adeelhussain opened this issue 1 year ago • 1 comments

Current Behavior

Right now we don't have any way of validating form, e.g i want to send data to my CRM which have some requirements for specific fields. Lets say we want to select email field to specific input but if have select invalid value, like date for the email input, then when the data is being sent my record will be break.

Desired Behavior / Feature Request

While mapping input fields with the data, we should be able to add custom validations for specific input.

like this

operation: { inputFields: [ { key: 'email', label: 'Email Address', type: 'string', required: true, helpText: 'Please enter a valid email address.', // Using a regular expression for validation validation: { regex: '^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$', errorMessage: 'Must be a valid email address.' } }, { key: 'zip_code', label: 'ZIP Code', type: 'string', required: true, helpText: 'Enter a 5-digit ZIP Code.', validation: { regex: '^\\d{5}$', errorMessage: 'ZIP Code must be exactly 5 digits.' } } ] }

adeelhussain avatar Jan 28 '25 13:01 adeelhussain

Instead of providing static regex validation, allow the action's perform method to add error messages to fields, like this:

export {
    display: {
		label: 'New Lead',
		description: 'Triggers when a new lead is created.',
	},

	operation: {
		perform: (z, bundle) => {
			if (!emailIsValid()) {
				throw new z.errors.ValidationError('Given data is invalid', {
					'email': ['Please enter a valid email address.']
				});
			}

			throw new z.errors.ValidationError('Given data is invalid', {
				'array.0.child': ['Please enter a valid email address.'],
				'other_field': ['Multiple', 'Errors'],
			});
		},
	},
}

oprypkhantc avatar Apr 24 '25 13:04 oprypkhantc

Hey @adeelhussain and @oprypkhantc 👋 Thank you for raising this issue and helping to improve the Zapier Developer Platform.

We've logged your feature request in our internal system for further review, and this issue is now closed here.

Going forward, please use our Developer Support form to request further updates, report issues, or request new features. That will ensure your enquiry is quickly handled by the right team.

Many thanks!

iscorer avatar Oct 03 '25 14:10 iscorer