• Resolved Chigolo

    (@fitnsexy)


    I’d like to have a date at the end of my form, displaying the current date next to it. Is there a way to automatically select the current date in a date field, or to manually select ONLY the current date?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Chigolo

    (@fitnsexy)

    Got it! (https://wpforms.com/developers/how-to-set-a-default-date-for-your-date-picker-form-field/)

    But is there a possibility to also get a todays date ONLY in the selection area?

    Thread Starter Chigolo

    (@fitnsexy)

    Another option would be to completely disable the date picker for this date field in the form, so that only today’s date is automatically preselected.

    Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @fitnsexy,

    Thanks for reaching out!

    It’s not possible to disable the date picker in a date field without risking issues with your form.

    If you’d like to have a field that displays today’s date at the end of your form, there are two options:

    1. If you have a Pro license or higher, you can use the now() function in a Single Line Text field. This way, the text field will display today’s date and be read-only. In case it helps, here’s our guide with details about the now() function.
    2. Alternatively, you can use a custom code snippet. For example, you can add the snippet below to display today’s date in a Single Line Text field:
    /**
     * Set today's date in a Single Line Text field and make it read-only in WPForms.
     */
    function wpf_dev_set_date_in_field() {
        ?>
        <script type="text/javascript">
          jQuery(document).ready(function($){
            // Replace '#wpforms-566-field_8' with the selector for your target field.
            var dateField = $('#wpforms-566-field_8');
            if (dateField.length) {
              var today = new Date();
              var day = String(today.getDate()).padStart(2, '0');
              var month = String(today.getMonth() + 1).padStart(2, '0'); // January is 0!
              var year = today.getFullYear();
              var dateString = year + '-' + month + '-' + day; // Format: yyyy-mm-dd
              dateField.val(dateString);
              dateField.prop('readonly', true);
            }
          });
        </script>
        <?php
    }
    add_action( 'wpforms_wp_footer_end', 'wpf_dev_set_date_in_field', 30 );

    Please update “566” with your Form ID, and “8” with your Single Line Text field ID.

    In case it helps, here’s our tutorial with the most common ways to add custom code like this. For the most beginner-friendly option in that tutorial, I’d recommend using the WPCode plugin.

    I hope this helps! Let me know if you have any further questions.

    Thread Starter Chigolo

    (@fitnsexy)

    Perfect! Thx for your outstanding support @rsouzaam

    Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @fitnsexy

    You’re very welcome, happy to help!

    It looks like you’ve marked this post as resolved. If you’d like more help with using WPForms, please feel free to reach out.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Only current ind date field’ is closed to new replies.