Skip to content

Instantly share code, notes, and snippets.

View jadealombro's full-sized avatar
👽

Jade jadealombro

👽
  • Montreal, Canada
View GitHub Profile
add_action( 'wpforms_wp_footer_end', function() { ?>
<script type="text/javascript">
;(function($) {
if( $('#wpforms-101')) {
$("#wpforms-101-field_5").on("input", function(){
var the_date = new Date($(this).val());
the_date.setDate(the_date.getDate() + 1);
$('#wpforms-740-field_25').val( the_date.toLocaleDateString('en-US') );
@jadealombro
jadealombro / wpf-disable-some-options.php
Last active April 21, 2022 14:01
Disable some checkboxes, radio buttons, and dropdown options in WPForms
<?php
add_action( 'wpforms_wp_footer_end', function () {
?>
<script type="text/javascript">
jQuery(function($){
// This array contains all the options that will be disabled
// 2217 is the form ID
// 1, 2, 3 after #wpforms-2217-field_ are the field IDs
@jadealombro
jadealombro / wpf-clickable-number-indicators.php
Last active October 7, 2021 13:27
This snippet makes the number indicators of a multi-page form clickable and to easily navigate to the pages.
<?php
// NOTE: This snippet is not perfect because it will not check for validations of the current page just like clicking the next button does
add_action( 'wpforms_wp_footer_end', function() {
?>
<style>
.wpforms-page-indicator-page-number {
transition: all 0.2s ease-in-out;
@jadealombro
jadealombro / wpf-block-names.php
Created October 3, 2021 14:36
This snippet stops the form from being submitted if the name matches any of the blocked names stored in an array.
<?php
add_action( 'wpforms_process_validate_name', function( $field_id, $field_submit, $form_data ) {
// Bail early if form ID is not 2090 and field ID is not 1
if ( absint( $form_data['id'] ) !== 2090 && $field_id !== 1 ) {
return;
}
$submitted_name = $field_submit['first'] .' ' .$field_submit['last'];
@jadealombro
jadealombro / wpf-set-minimum-word-count.php
Last active September 27, 2021 09:04
Set a minimum word count for inputs to a Single Text Field in WPForms.
<?php
add_action( 'wpforms_process_validate_text', function( $field_id, $field_submit, $form_data ) {
// Optional, you can limit to specific forms. Below, we restrict output to
// form ID #2056 and field ID #5
if ( absint( $form_data['id'] ) !== 2056 && $field_id !== 5 ) {
return;
}
@jadealombro
jadealombro / wpf-log-values-wpforms-process-complete.php
Last active September 27, 2021 09:06
Log values in the wpforms_process_complete hook.
<?php
// Make sure to turn the WordPress debug mode
// https://wordpress.org/plugins/wp-debugging/
add_action( 'wpforms_process_complete', function( $fields, $entry, $form_data, $entry_id ) {
error_log( var_export( $form_data, true ) );
}, 10, 4 );
@jadealombro
jadealombro / wpf-set-default-option-value.php
Last active September 27, 2021 09:06
This snippet is an example of how to programmatically set a default selected value in a dropdown and multiple choice field in WPForms.
<?php
add_filter( 'wpforms_field_data', ( $field, $form_data ) {
if ( absint( $form_data['id'] ) !== 2067 || absint( $field['id'] ) !== 5 ) {
return $field;
}
$default_field_value = 'Second Choice';
@jadealombro
jadealombro / wpf-auto-next-page.php
Last active August 12, 2021 15:26
This script will only work specifically for form 41 with one multiple choice (image choices) field on each page.
<?php
add_action( 'wpforms_wp_footer_end', function() { ?>
<script type="text/javascript">
;(function($) {
$( "#wpforms-form-41 .wpforms-field-radio li" ).on( "click", function() {
$(this).closest('.wpforms-page').find('.wpforms-page-next').click();
});
})(jQuery);
</script>
@jadealombro
jadealombro / wpf-restrict-letters-in-phone-field.php
Last active August 1, 2021 16:13
This code will restrict letters/alphabet from being typed in the WPForm's Phone field.
<?php
function restrict_letters_in_phone_field( ) {
?>
<script type="text/javascript">
;(function($) {
$('.wpforms-field-phone input').bind('input', function() {
var c = this.selectionStart,
r = /^[A-Za-z]+$/,
v = $(this).val();
@jadealombro
jadealombro / wpf-align-prev-and-submit-button.php
Created July 28, 2021 17:41
This snippet will align the last previous button and the submit button in a multi-page form in WPForms.
function move_submit_button( ) {
?>
<script type="text/javascript">
;(function($) {
$(".wpforms-submit-container").appendTo('.wpforms-field-container .wpforms-page.last .wpforms-pagebreak-left');
})(jQuery);
</script>
<style>
.wpforms-field-container .wpforms-page.last .wpforms-pagebreak-left {
display: flex;