JSPM

  • Created
  • Published
  • Downloads 176
  • Score
    100M100P100Q84051F
  • License MIT

A component to take GraphQl Gravity Forms query data from WordPress and return a usable form.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (next-gravity-forms) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Next JS Gravity Forms Component

    A plug and play component for parsing GraphQL Gravity Form data. Outputs a component using BEM classes, meaning all you need to do is style it.

    To be used alongside wp-graphql-gravity-forms (version 0.12.0 up).

    Uses React Hook Forms under the hood for all that good state management.

    Installation

    # Install the component
    yarn add nextjs-gravity-forms
    
    # Or with NPM
    npm i nextjs-gravity-forms

    How To Use

    Add the env variable to your project: NEXT_PUBLIC_WORDPRESS_API_URL. Add your domain to it. i.e. NEXT_PUBLIC_WORDPRESS_API_URL=https://www.YOURWPSITE.com/graphql.

    This variable is called internally by the getGravityForm function.

    Import the component and use it with the API function. Select the required form using its databaseId.

    import GravityFormForm, { getGravityForm } from "next-gravity-forms";
    
    const data = await getGravityForm(1);
    
    return <GravityFormForm data={data} />;

    Passing in Preset Values

    Sometimes you will want to conditionally set default values, or pass in data to hidden fields. This could be values for a user ID, or a current page.

    This is handled by the presetValues prop.

    <GravityFormForm data={form} presetValues={{ input_2: "My preset value" }} />

    In the above example input_2 corresponds to the 2nd field added in the WordPress Gravity Forms edit page. This value can be found by clicking on the field and looking at the top right just under Field Settings.

    WordPress Backend Not Allowing Submission

    Having CORS issues?

    Add the following snippet of code to your WordPress functions.php file.

    Make sure to update the 'https://yourfrontendurl.com' to your actual frontend. With no trailing slash.

    add_filter( 'graphql_response_headers_to_send', function( $headers ) {
        return array_merge( $headers, [
            'Access-Control-Allow-Origin'  => 'https://yourfrontendurl.com',
            'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE',
            'Access-Control-Allow-Credentials' => 'true'
        ] );
    } );

    Implementing Google reCAPTCHA

    On your WordPress backend within the Gravity Forms settings set up reCaptcha. Follow the instructions provided by Gravity Forms.

    Testing & Developing

    Firstly, yes please! Any help would be great.

    To Do

    Field Components

    • Input
      • Email - Confirmation Email
    • Textarea
    • Select (half done, need to add default values)
    • Multiselect
    • Number
    • Checkbox (half done, need to add default values)
    • Radio (half done, need to add default values and correct error placement)
    • Hidden
    • HTML
    • Captcha
    • Add masking to inputs
    • Section
    • Page
    • Date
    • File upload
    • Post Fields
    • Pricing Fields
    • Phone
    • Email
    • Configure error message (currently just 'An Unknown Error Occurred')
    • Integrate Success/Failure Handler from previous plugin

    General Form

    • Honeypot
    • Save and Continue
    • Add submit/error callback for custom use

    Add Tests to Inputs

    • Input
    • Textarea
    • Select (half done, need to add default values)
    • Multiselect
    • Number
    • Checkbox (half done, need to add default values)
    • Radio (half done, need to add default values)
    • Hidden
    • HTML
    • Captcha

    Confirmations

    • Text Confirmation
    • Page Change
    • Redirect
    • Redirect query strings
    • Conditional Logic

    Known Issues

    • Invalid phone number results in failed submission w/ non-descript general error message.