Skip to content

Instantly share code, notes, and snippets.

View faisalahammad's full-sized avatar
🎯
Focusing

Faisal Ahammad faisalahammad

🎯
Focusing
View GitHub Profile
@faisalahammad
faisalahammad / disable-gravity-forms-email-notification-zero-donation.php
Created November 13, 2025 08:40
Disable Gravity Forms email notification when donation amount is zero or $0.00. This PHP snippet stops email alerts if users select “Other Amounts” and enter 0 in Gravity Forms. Easy to add in your child theme’s functions.php or via Code Snippet plugin. Works with any form by updating form ID and notification ID.
<?php
/**
* Disable Gravity Forms email notification when "Other Amounts" is 0 or $0.00.
*
* Replace '3' with your Gravity Form ID.
* Replace '6915837c16509' with your Notification ID (nid).
*
* @author faisalahammad <me@faisalahammad>
* @ticket https://community.gravityforms.com/t/using-conditional-logic-to-not-send-confirmation-email/19851/
*/
@faisalahammad
faisalahammad / ninja-forms-auto-email-copy-jquery.md
Created September 22, 2025 10:34
Auto copy email from one field to multiple fields in Ninja Forms WordPress plugin. jQuery solution for business email duplication across billing, support, marketing fields. Copy email address automatically with checkbox control and editable overrides.

Ninja Forms Auto Email Copy - jQuery Solution

This jQuery script automatically copies an email address from one field to multiple other fields when a checkbox is checked. Perfect for forms where users want to use their business email for multiple purposes (billing, support, marketing, etc.).

Features

  • ✅ Copy email from main field to multiple target fields
  • ✅ Real-time updates when main email changes
  • ✅ Fields remain editable for user overrides
  • ✅ Clears target fields when checkbox is unchecked
  • ✅ Waits for DOM elements to load properly
@faisalahammad
faisalahammad / ninja-forms-phone-export-unescape-plus.php
Created September 15, 2025 05:30
Prevents the core CSV export from keeping a leading apostrophe for phone numbers that start with a plus sign (e.g. +441234567890). This snippet detects values like "'+441234..." added by CSV-escaping and removes the leading apostrophe only when the rest of the value matches a reasonable phone pattern.
<?php
/**
* Ninja Forms phone export unescape plus
*
* Prevents the core CSV export from keeping a leading apostrophe for phone numbers that start with a plus sign (e.g. +441234567890). This snippet detects values like "'+441234..." added by CSV-escaping and removes the leading apostrophe only when the rest of the value matches a reasonable phone pattern.
* @author Faisal Ahammad <me@faisalahammad.com>
*/
add_filter('ninja_forms_subs_export_field_value_phone', function ($value, $field) {
// Normalize to string
@faisalahammad
faisalahammad / ninja-forms-uploads-file-cleanup.php
Last active September 12, 2025 06:44
Ninja Forms photo cleanup cron PHP script — schedule automated removal of uploaded images every 15 days. This simple WordPress snippet creates a custom cron schedule, triggers an immediate cleanup on first run, walks Ninja Forms upload folders, and deletes common image types (jpg, jpeg, png, gif, bmp, webp, svg). Includes safe filesystem usage a…
<?php
/**
* Ninja Forms Uploads File Cleanup every 15 days
* @author Faisal Ahammad <me@faisalahammad.com>
*/
function schedule_ninja_forms_photo_cleanup() {
if ( ! wp_next_scheduled( 'ninja_forms_photo_cleanup_event' ) ) {
// Run immediately first time, then every 15 days
cleanup_ninja_forms_photos();
@faisalahammad
faisalahammad / ninja-forms-minlength-validation-php.php
Created September 12, 2025 03:07
Ninja Forms minlength validation PHP snippet — custom server-side validation for Ninja Forms to enforce minimum character length on a specific field.
<?php
/**
* Ninja Forms minlength validation
* @author Ron Rosenthal
*/
add_filter('ninja_forms_submit_data', 'custom_ninja_forms_minlength_validation');
function custom_ninja_forms_minlength_validation($form_data) {
// Specify the field ID and minimum length
@faisalahammad
faisalahammad / ninja-forms-strong-password-enforce.php
Created September 8, 2025 03:36
Enforce strong password for Ninja Forms User Management (register/update) — WordPress snippet that validates passwords (8+ chars, uppercase, lowercase, number, special) for Ninja Forms register-user and update-profile actions. Paste into theme functions.php or use a code snippets plugin.
<?php
/**
* Enforce strong passwords for Ninja Forms user registration and profile update actions.
* @description Enforce strong password for Ninja Forms User Management (register/update) — WordPress snippet that validates passwords (8+ chars, uppercase, lowercase, number, special) for Ninja Forms register-user and update-profile actions. Paste into theme functions.php or use a code snippets plugin.
*
* @author Faisal Ahammad <me@faisalahammad.com>
*/
add_filter('ninja_forms_submit_data', function ($form_data) {
if (!function_exists('Ninja_Forms')) {
@faisalahammad
faisalahammad / ninja-forms-open-redirect-in-new-tab.js
Last active August 31, 2025 03:32
Open Ninja Forms redirect URL in a new tab — PHP code snippet to open the redirect URL in a new tab after form submission
/**
* Open Ninja Forms redirect URL in a new browser tab after form submission.
* @author Faisal Ahammad <me@faisalahammad.com>
*/
jQuery(document).ready(function($) {
if (typeof nfRadio !== 'undefined') {
nfRadio.channel('forms').on('submit:response', function(response, textStatus, jqXHR, formId) {
if (response && response.data && response.data.actions && response.data.actions.redirect && response.data.actions.redirect !== '') {
var redirectUrl = response.data.actions.redirect;
@faisalahammad
faisalahammad / ninja-forms-phone-field-starting-digits-blocker.js
Created August 20, 2025 05:08
Ninja Forms phone validation to block specific starting numbers (0, 1, 88) — prevent phone inputs starting with blocked digits on masked Ninja Forms fields
/**
* Ninja Forms Phone Starting Digits Blocker
* @author Faisal Ahammad <me@faisalahammad.com)
*/
jQuery(document).ready(function($) {
// Configuration: Add numbers you want to block from starting the phone number
const BLOCKED_STARTING_NUMBERS = ['0', '1', '88'];
@faisalahammad
faisalahammad / fix-ninja-forms-multiselect-behavior.js
Created August 4, 2025 09:49
Fix Ninja Forms Multi-Select option selection Issue. Prevent Default Selection & Enable Proper Multi-Select Handling in Forms.
jQuery(document).ready(function($) {
function fixMultiSelect() {
$('select[multiple].ninja-forms-field:not([data-fixed])').each(function() {
$(this).attr('data-fixed', 'true')
.on('mousedown', function(e) {
e.preventDefault();
if (e.target.tagName === 'OPTION') {
var $opt = $(e.target);
$opt.prop('selected', !$opt.prop('selected'));
$(this).trigger('change').trigger('input');
@faisalahammad
faisalahammad / ninja-forms-file-upload-limit-text-translate.php
Created July 14, 2025 15:29
Custom Ninja Forms PHP snippet to set maximum file upload limit message – Easily restrict file uploads with customized user notification in Ninja Forms plugin for WordPress.
<?php
// Customize the "Max x files are allowed" message in Ninja Forms File Uploads
add_filter( 'ninja_forms_uploads_js_strings', 'custom_ninja_forms_uploads_js_strings' );
function custom_ninja_forms_uploads_js_strings( $strings ) {
// Change default message to German: "Max %n Dateien sind erlaubt"
$strings['file_limit'] = __( 'Max %n Dateien sind erlaubt', 'ninja-forms-uploads' );
return $strings;
}