Skip to content

Latest commit

History

59 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

LightWeightPopup (PHP & Ajax Custom Popup)

A simple, lightweight jQuery-based popup plugin to display any kind of HTML data (contact forms, alert messages, iframes, etc.) using AJAX or inline content.

This plugin is designed to be a footprint-free alternative to heavy plugins, giving you only the features you actually need.

🚀 Features

  • Lightweight: Minimal code for maximum performance.
  • Versatile: Supports AJAX, Inline HTML, and Iframes.
  • Customizable: Set width, height, titles, and overlays via parameters or data-attributes.
  • Callbacks: Supports beforeOpen, openComplete, and closeComplete events.

🛠 Installation

1. Include Stylesheet & Scripts

Add the CSS in your <head> and the JS files before the closing </body> tag. This plugin requires jQuery.

<linkrel="stylesheet" href="https://cdn.jsdelivr.net/gh/LearnCodeWeb/lightWeightPopup@v-0.5/css/lightWeightPopup.min.css" type="text/css"><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script><scriptsrc="https://cdn.jsdelivr.net/gh/LearnCodeWeb/lightWeightPopup@v-0.5/js/lightWeightPopup.min.js"></script>

📖 How to Use

HTML Structure

You can trigger the popup using buttons or anchor tags. Use data-attributes for quick configuration.

<buttontype="button" class="btn btn-primary open-popup" data-href="contact-us.html" data-content="ajax">
Open Ajax Form
</button><buttontype="button" id="inline" class="btn btn-danger" data-content="inline">
Click for Inline Content
</button><buttontype="button" id="iframe" data-href="[https://www.youtube.com/embed/ZwKhufmMxko](https://www.youtube.com/embed/ZwKhufmMxko)" data-content="iframe">
Open Video
</button>

Plugin Initialization

Initialize the plugin in your custom script:

$(document).ready(function(e){$('.open-popup').lightWeightPopup({title: 'Popup Title',width: '500px',top: '50',overlay: true,type: 'ajax',beforeOpen: function(){console.log('Opening...');},openComplete: function(){console.log('Opened!');}});// Basic Ajax Call$('#popup').lightWeightPopup({type: 'ajax',href: 'contact-us.html',width: '90%',maxWidth: '600px'});});

⚙️ Parameters (Options)

OptionDescriptionData Attribute
hrefURL for Ajax or Iframedata-href
widthPopup width (px or %)data-width
heightPopup heightdata-height
maxWidthMaximum widthdata-maxWidth
titleTitle of the modaldata-title
overlayClose on background click (default: false)data-overlay
modelFixedFix model at the topdata-model-fixed

📝 Example Contact Form (HTML)

If you are using Bootstrap 4, you can use this structure inside your Ajax-loaded file (contact-us.html):

<divclass="p-3"><formmethod="post"><divclass="form-group"><label>First Name</label><inputtype="text" name="fname" class="form-control" placeholder="Enter first name"></div><divclass="form-group"><label>Email</label><inputtype="email" name="email" class="form-control" placeholder="Enter email"></div><divclass="form-group"><label>Message</label><textarearows="5" name="message" class="form-control" placeholder="Write here..."></textarea></div><buttontype="button" class="btn btn-danger">Submit</button></form></div>

👨‍💻 Author

Zaid Bin Khalid


📄 License

This project is open-source. Please feel free to use and modify it for your projects.

About

How to create a custom POPUP form with PHP & Ajax

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages