Archives: Snippets
How to Automatically Redirect If User Is Already Logged In
/** * Automatic redirect from login form if a user is already logged in * * @link https://wpforms.com/developers/how-to-automatically-redirect-if-user-is-already-logged-in/ */ function redirect_to_specific_page() { // enter the page ID of the page that contains the login form $page_id = 345; // Change…Continue reading
How to Add an Input Mask to the International Postal Code
/* * Custom input mask for the address field’s international scheme. * * @link https://wpforms.com/developers/how-to-add-an-input-mask-to-the-international-postal-code */ function wpf_dev_address_field_properties( $properties, $field, $form_data ) { if($field[ ‘scheme’ ] === ‘international’) { $properties[ ‘inputs’ ][ ‘postal’ ][ ‘class’ ][] = ‘wpforms-masked-input’; $properties[ ‘inputs’…Continue reading
How to Use Conditional Logic With a Date Picker
/** * Use conditional logic with a date field to show or hide another form field * * @link https://wpforms.com/developers/how-to-use-conditional-logic-with-a-date-picker/ */ add_action( ‘wp_head’, function () { ?>Continue reading
How to Disable Browser Autocomplete for Form Fields – specific fields
/** * Disable autocomplete for a specific form and field ID * * @link https://wpforms.com/developers/disable-browser-autocomplete-for-form-fields/ */ function wpf_disable_email_autocomplete( $properties, $field, $form_data ) { // This check will only disable autocomplete for Field #3 inside Form #11. // Removing this check…Continue reading
How to Disable Browser Autocomplete for Form Fields – all fields
/** * Disable form autocomplete for all fields on a specific form * * @link https://wpforms.com/developers/disable-browser-autocomplete-for-form-fields/ */ function wpf_dev_disable_form_autocomplete( $form_atts, $form_data ) { // This check will only form autocomplete for Form #11. // Removing this check would disable autocomplete…Continue reading
How to Customize the Labels for Image Choices – Combined effect
form#wpforms-form-1000 .wpforms-field .wpforms-image-choices-item:hover .wpforms-image-choices-label { position: absolute; top: 0; left: 50%; transform: translateX(-50%); background-color: #f6f6f6; color: #333; padding: 20%; border-radius: 5px; opacity: 1; transition: opacity 0.3s ease-in-out; width: 100%; height: 100%; } form#wpforms-form-1000 .wpforms-image-choices label:hover { border: none; box-shadow: none;…Continue reading
How to Customize the Labels for Image Choices
/* Position labels over images and hide them by default */ form#wpforms-form-1000 .wpforms-field .wpforms-image-choices-label { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.7); text-align: center; display: flex; justify-content: center; align-items: center; opacity: 0;…Continue reading
How to Perform Field Comparisons Within Your WPForms
/** * Perform Field Comparisons * * @link https://wpforms.com/developers/how-to-perform-field-comparisons-within-your-wpforms/ */ function wpf_dev_compare_fields( $fields, $entry, $form_data ) { // Only run this snippet on the form ID 1000 if ( absint( $form_data[ ‘id’ ] ) !== 1000 ) { return $fields;…Continue reading
How to Add BCC to Email Notifications (for all forms)
add_filter( ‘wp_mail’, function ( $args ) { // Add the BCC email address here $bcc_address = ‘Bcc: [email protected]’; if ( ! empty( $args[ ‘headers’ ] ) ) { if ( ! is_array( $args[ ‘headers’ ] ) ) { $args[ ‘headers’…Continue reading