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 / 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;
}
@faisalahammad
faisalahammad / ninja-forms-elementor-pro-recaptcha-v3-fix.php
Created July 9, 2025 14:26
PHP snippet to fix Google reCaptcha v3 loading issue in Ninja Forms with Elementor Pro. This workaround ensures proper reCaptcha script enqueue using Ninja Forms settings and supports multilingual options. Ideal for WordPress developers facing reCaptcha conflicts between Ninja Forms and Elementor Pro plugins.
<?php
/**
* Fix Google reCaptcha v3 loading issue in Ninja Forms with Elementor Pro.
*
* @author Faisal Ahammad <me@faisalahammad.com>
*/
add_filter('ninja_forms_pre_enqueue_recaptcha_v3_js', 'nfele_enqueue_recaptcha_v3_js');
function nfele_enqueue_recaptcha_v3_js()
@faisalahammad
faisalahammad / ninja-forms-set-default-hour-in-date-time-field.js
Created July 9, 2025 12:52
Use this jQuery script to automatically set the default selected option to "09" for hour dropdowns in Ninja Forms plugin Date/Time field. This code waits until elements with class `.setdefaulttime` appear on the page, then targets `<select>` elements with IDs starting with `hour-select-` or class `.hour.extra` and selects the option with value "…
/**
* Set default hour to 09:00 for date/time fields in Ninja Forms
*
* @author Faisal Ahammad <me@faisalahammad.com>
*
* First add the "setdefaulttime" CSS class in the Date/Time → Display → Container to make this code work.
*/
jQuery(document).ready(function($) {
function checkAndSetHour() {
@faisalahammad
faisalahammad / gravity-forms-apc-auto-resave.php
Created July 8, 2025 17:23
Automatically re-saves posts created via Gravity Forms Advanced Post Creation add-on after 5 and 10 seconds to fix social sharing image issues. Includes force cron functionality for testing.
<?php
/**
* Gravity Forms Advanced Post Creation Auto Resave
*
* This code automatically resaves posts created by the Gravity Forms Advanced Post Creation add-on.
* It ensures that the post is properly saved and updated in the database.
* Visit https://yoursite.com/?force_cron if the code doesn’t run automatically. This URL will force the cron to run.
*
* @author Faisal Ahammad <me@faisalahammad.com>
*/
@faisalahammad
faisalahammad / gravityforms-redirect-to-created-post.php
Created July 8, 2025 12:51
This snippet demonstrates how to automatically redirect users to the newly created post after submitting a Gravity Forms form using the Advanced Post Creation add-on in WordPress. Perfect for guest post submissions, this code ensures users are sent directly to their published post upon form submission.
<?php
/**
* Gravity Forms: Redirect to Newly Created Post After Submission
*
* @author Faisal Ahammad <me@faisalahammad.com>
*
* Replace 123 with your actual Gravity Form ID.
*/
add_filter( 'gform_confirmation_123', 'gfapc_redirect_to_created_post', 10, 4 );
@faisalahammad
faisalahammad / ninja-forms-select-image-rearrange-label-image-position.js
Created June 2, 2025 17:18
A jQuery script to rearrange images and labels for the Select Image field in Ninja Forms. This code ensures images appear above the label text by swapping their positions dynamically. It waits for Ninja Forms to fully load before applying the changes, adds a 5px bottom margin to images, and is optimized for WordPress compatibility.
/**
* Rearranges label and image elements in the Select Image field
* @author Faisal Ahammad <me@faisalahammad.com>
*/
jQuery(document).ready(function ($) {
function waitForLabels() {
if ($(".listimage-container label").length) {
$(".listimage-container label").each(function () {
var $this = $(this);
@faisalahammad
faisalahammad / ninja-forms-change-placeholder-text-color.css
Created May 1, 2025 10:40
A simple way to change the placeholder text color in your form fields by adding CSS in Field Name → Styles → Wrap Styles → Advanced CSS, making sure to enable the "Show Advanced CSS Properties" option. The example CSS covers different browsers and lets you customize the placeholder text color by changing the color code. Please note that to add c…
input::placeholder {
color: #000;
}
input::-webkit-input-placeholder {
color: #000;
}
input::-moz-placeholder {
color: #000;