Git Product home page Git Product logo

bolt-newsletter-subscription's Introduction

Newsletter Subscription Extension

"Newsletter Susbscription" is a small extension to save registered emails in database. Use it by simply placing the following in your template, for example, inside a script tag at the bottom of the page, and make whatever use you need with returning values:

{{ checknewsletter() }}

The extension will first email users with a link so thay can verify themselves. Once verified, the status of the database record will be "Published".

You are free to create the subscription form. Just take into account to set "POST" as form method and, obvioulsy, include the field name set in config.yml as an input form control.

The default form field is "newsletter_email". You can customize it by editing the config.yml file.

newsletter_field: another_name

You can also customize the subject field of the email sent and a small sentence in the email's body.


Be sure to setup email smtp settings in your Bolt config file, so the extension can send verifying emails.

Right now you need to manually create the content type for this extension. As an example:

subscribers:
    name: Subscribers
    singular_name: Subscriber
    fields:
        email:
            label: Email
            type: text
            group: Content
        token:
            label: Token
            type: text
            readonly: true
            class: narrow
    viewless: true
    default_status: held
    searchable: false
    show_on_dashboard: false

Returned values:

When inserting a new subscriber
    0: Verifying email sent. All OK
    1: Error sending verifying email
    2: Error saving subscriber email in DB
    3: Subscriber email already registered
    99: Subscriber email not valid
    
When verifying an email
    10: Subscriber email verified
    11: Error saving verified email info to DB
    12: Error in subscriber email or token sent for verifying 

This extension does not force any form style or similar. It lets you create the email subscription form freely. You just need to include the field set in config.yml. Additionally, it just inform you about the status of the action using raw numeric strings (returned values), so you later can do whatever you want with them (for example, compare them and make use of modals to inform the user, but you are free to make whatever you want).

For example: Inserting a script tag in the bottom of the page (jQuery ready version)...

<script>
 var res = '{{ checknewsletter() }}';
 $(document).ready(function(){
    switch(res){
        case '0':
            alert('Verification email sent.');
            break;
        case '1':
            alert('Error sending verification email.');
            break;
        case '2':
            alert('Error saving subscriber to database.');
            break;
        case '3':
            alert('Subscriber email already registered.');
            break;
        case '99':
            alert('Subscriber email not valid.');
            break;
        case '10':
            alert('Subscriber email verified.');
            break;
        case '11':
            alert('Error saving verified subscriber to database.');
            break;
        case '12':
            alert('Error in subscriber email or token sent for verifying.');
            break;
    }
 });
</script>

bolt-newsletter-subscription's People

Contributors

miguelavaqrod avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.