Customizing Date Format

Overview

A common issue users encounter is that date fields in PDF forms aren’t being filled correctly, even when all other fields work fine. This typically happens because the date format from WPForms doesn’t match what the PDF field expects.

This guide will show you how to properly configure date fields to ensure they are correctly filled in your PDF forms.

Common Date Field Issues

The most common reason for PDF date fields not getting filled is that the date format in your WPForms field doesn’t match the format expected by the PDF field. It’s critical that the format of your WPForms date field exactly matches the format of your PDF form field, or the field will not be filled.

Setting Up Date Formats in WPForms

WPForms provides three default date formats in the Date / Time field’s Date Picker, but you can add custom formats to match your PDF requirements. Here’s how to set up your date fields:

  1. First, create a WPForms Date / Time field and set it to the format that matches your PDF field format.

  2. If none of the default formats match your PDF field format, you’ll need to add a custom format using code. Add this snippet to your site’s functions.php file or a custom plugin:

    /**
     * Add additional formats for the Date field Date Picker
     */
    function wpf_dev_date_field_formats($formats) {
        // Add your custom format here
        // For example, to add dd/mm/yyyy format:
        $formats['d/m/Y'] = 'd/m/Y';
    
        return $formats;
    }
    add_filter('wpforms_datetime_date_formats', 'wpf_dev_date_field_formats', 10, 1);
    
  3. After adding the code, create or edit your form and select your custom date format in the Date / Time field settings.

  4. Map this field to the corresponding PDF field using the Field Mapper Tool.

Important Notes About Date Formats

  1. The format attribute only works with the Date / Time field - It is not a general formatting option for other field types.

  2. Format must match exactly - The date format in your WPForms field must exactly match the format expected by your PDF field.

  3. Custom formats require code - If you need a format not provided by default, you’ll need to add the code snippet shown above.

Date Format Conversion Table

The WPForms date format uses PHP date format strings, while PDF date formats use a different scheme. The following table can be used for converting PDF date format strings to PHP date format strings for use in WPForms.

PDF PHP Format Example
m/d n/j 6/27
m/d/yy n/j/y 6/27/22
mm/dd/yy m/d/y 06/27/22
mm/yy m/y 06/22
d-mmm j-M 6-Jun
d-mmm-yy j-M-y 6-Jun-22
dd-mmm-yy d-M-y 27-Jun-22
dd/mm/yy d/m/y 27/06/22
dd/mm/yyyy d/m/Y 27/06/2022
dd.mm.yyyy d.m.Y 27.06.2022
yy-mm-dd y-m-d 22-06-27
mmm-yy M-y Jun-22
mmmm-yy F-y June-22
mmm d, yyyy M j, Y Jun 27, 2022
mmmm d, yyyy F j, Y June 27, 2022
m/d/yy h:MM tt n/j/y g:i a 6/27/22 1:24 pm
m/d/yy HH:MM n/j/y H:i 6/27/22 13:25
yyyy-mm-dd Y-m-d 2022-06-27

For more information on creating custom date formats in WPForms, see the WPForms Developer Documentation on Date Formats.

Testing Your Date Fields

After setting up your date fields and mapping them to your PDF, it’s essential to test the form to ensure the dates are being correctly filled in the PDF. Submit a test entry and check if the date appears correctly in the filled PDF.