Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

spemailhandler

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spemailhandler

A script to handle the interaction between a Bootstrap-based contact form and the server, handling form submission and feedback.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
228
increased by33.33%
Maintainers
0
Weekly downloads
 
Created
Source

SPEmailHandler - Contact Form Script

SPEmailHandler is a simple contact form handler that uses Bootstrap's modal for success feedback and manages form validation and submissions via JavaScript.

Installation

To use this script, you’ll need:

  • Bootstrap (for styling and modal functionality)
  • SPEmailHandler (imported as a module)

Install SPEmailHandler from npm:

npm install spemailhandler

Then, in your JavaScript:

import { ContactForm } from "spemailhandler";

const formHandler = new ContactForm("/path/to/your-server-script.php");

HTML Structure

The following HTML structure is required for SPEmailHandler to function correctly. Be sure to use the correct id and class attributes as the script depends on these identifiers.

Form Fields:

Name Input:

<input type="text" id="name" placeholder="Your Name">

Email Input:

<input type="email" id="email" placeholder="Your Email">

Message Input:

<textarea id="message" placeholder="Your Message"></textarea>

Submit Button:

<button id="sendmessage">Send Message</button>

Cancel Button (for modal)

<button id="contactCancel" data-bs-dismiss="modal">Cancel</button>

Alert and Modal

Alert for Displaying Errors

<div id="message-alert" style="display: none;"></div>

Success Modal

<div class="modal fade" id="success" tabindex="-1" aria-labelledby="successLabel" aria-hidden="true">
    Success Message
</div>

How to Use

Initialize the Contact Form

After including the necessary HTML elements and Bootstrap modal, initialize ContactForm by passing the URL of your server-side script that handles form submissions.

const formHandler = new ContactForm("/path/to/your-server-script.php");

Form Validation and Submission

  • Email Validation: The script validates email format before submission.
  • SPEmailHandler: Both the email and message fields must be filled out. If not, an alert displays prompting users to complete the fields.

Error Handling

  • If there is an issue with the server response, a default error message is displayed in #message-alert.
  • You can customize the error message by modifying the server-side response.

Server-Side Script Requirements

The server script should return a JSON response in the following format:

{
  "status": "success", // or "error"
  "message": "Optional error message"
}

Example

<form id="contact-form">
    <input type="text" id="name" placeholder="Your Name">
    <input type="email" id="email" placeholder="Your Email">
    <textarea id="message" placeholder="Your Message"></textarea>
    <div id="message-alert" style="display: none;"></div>
    <button id="sendmessage">Send Message</button>
</form>

<div class="modal fade" id="success" tabindex="-1" aria-labelledby="successLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="successLabel">Success</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                Your message has been sent successfully!
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

Keywords

FAQs

Package last updated on 16 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc