# give/4.18.0/src/DonationForms/resources/app/utilities/handleValidationRequest.ts

GiveWP – Donation Plugin and Fundraising Platform, version 4.18.0. 52 lines.

- Page: https://pluginprobe.com/plugins/give/4.18.0/code/src/DonationForms/resources/app/utilities/handleValidationRequest.ts
- Raw: https://pluginprobe.com/plugins/give/4.18.0/raw/src/DonationForms/resources/app/utilities/handleValidationRequest.ts
- Modified: 2026-09-23T17:56:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/give/4.18.0/code/src/DonationForms/resources/app/utilities/handleValidationRequest.ts#L10-L20`.

```typescript
import {Gateway, isFormResponseGatewayError, isFormResponseValidationError} from '@givewp/forms/types';
import generateRequestErrors from '../utilities/generateRequestErrors';
import FormRequestError from '../errors/FormRequestError';

import {__} from '@wordpress/i18n';
import {FieldValues, UseFormSetError} from 'react-hook-form';
import postFormData from '@givewp/forms/app/utilities/postFormData';
import convertValuesToFormData from '@givewp/forms/app/utilities/convertValuesToFormData';
import {getAuthToken} from '@givewp/forms/app/utilities/authToken';

/**
 * @since 4.17.0 Send the auth token so embedded forms stay signed in without cookies
 * @since 3.0.0
 */
export default async function handleValidationRequest(
    validateUrl: string,
    values: FieldValues,
    setError: UseFormSetError<FieldValues>,
    gateway?: Gateway
) {
    if (gateway !== undefined && values?.donationType === 'subscription' && !gateway.supportsSubscriptions) {
        return setError('FORM_ERROR', {
            message: __(
                'This payment gateway does not support recurring payments, please try selecting another payment gateway.',
                'give'
            ),
        });
    }

    try {
        const formData = convertValuesToFormData({...values, authToken: getAuthToken()});

        const {response} = await postFormData(validateUrl, formData);

        const formResponse = await response.json();

        if (isFormResponseGatewayError(formResponse) || isFormResponseValidationError(formResponse)) {
            throw new FormRequestError(formResponse.data.errors.errors);
        } else {
            return true;
        }
    } catch (error) {
        if (error instanceof FormRequestError) {
            return generateRequestErrors(values, error.errors, setError);
        }

        return setError('FORM_ERROR', {
            message: error?.message ?? __('Something went wrong, please try again or contact support.', 'give'),
        });
    }
}

```
