NPM Submission

Easily extend your Slapforms to use NPM instead of the default HTML form.

What is an NPM submission

NPM is a package manager for Node.js modules. We have a customized package on NPM for Slapform that you can use as an alternative to HTML Forms or AJAX Forms.

This is significant and has a few major benefits:

  1. Our NPM module is a lot smaller than jQuery.
  2. You can now use Slapform serverside, not just on a website/frontend!

An NPM module submission is like an AJAX submission, but instead of using jQuery's AJAX you can use our custom NPM module.

NPM Example

First, you need to decide how you will include the Slapform library in your project.

You can install the module using a CDN or via NPM. You should use the CDN if your code will live in a browser environment and use the NPM module if your code will live in a backend environment like a Node.js server.

Compatible with Webpack & Browserify

Slapform is 100% compatible with Webpack & Browserify. You should be using Webpack or Browserify if you are using NPM modules client-side or on a website. Read more about Webpack here.

Install Slapform via a CDN

    
      <script src="https://cdn.jsdelivr.net/npm/slapform"></script>
      <script type="text/javascript">
        var slapform = new Slapform(); // The script above exposes the global variable 'Slapform'
      </script>
    
  

Install Slapform via NPM

    
      npm install slapform
    
  
    
      const slapform = new (require('slapform'));
    
  

Using Slapform to Make Submissions

After you have followed the install step, you can start using Slapform with your website or software!

Copy-paste this code and just change [email protected] to your own email.

    
      slapform.submit({
        account: '[email protected]', // Replace this with the email that submissions should be sent to
        data: { // The data you want submitted and emailed to you
          name: 'Jon Snow',
          message: 'Hello World!'
          /* Name triggers */
          slap_subject: 'My Favorite Message',
          slap_replyto: '[email protected]'
          slap_debug: false,
          slap_webhook: 'https://yourwebsite.com/webhook',
          slap_honey: ''
          /* These Slapform Name Triggers exist but aren't applicable to AJAX submissions */
          // slap_redirect: 'https://yourwebsite.com',
          // slap_captcha: false,
        }
      })
      .success(function (response, data) { // This function runs only on success
        console.log('Success!', response, data);
      })
      .error(function (response, error) { // This function runs only on error
        console.log('Fail!', response, error);
      })
      .always(function (response) { // This function runs regardless of success or error
        console.log('This always runs!', response);
      });
    
  

Extending Slapform

Slapform can be easily extended to do some pretty advanced stuff:

  1. Include advanced name triggers to customize the email, push webhooks, and more
  2. Go beyond forms and submit data with AJAX. Learn how to submit AJAX
× You are using an outdated browser that our site DOES NOT support. Please click here to update your browser.