• Resolved lucari

    (@lucari)


    Hello and thanks for your plugin, I’m using it for a while, especially on this website (the subscription form is the footer, in a popup, in all products details and also in the checkout page )
    In the subscription form I added a custom input for birthday like this

    <input type="date" name="BIRTHDAY" required />

    but I notice that very often, the birthday recorded in Mailchimp is 01/01 instead of the real date that the user prompts.
    I tried other ways like these two

    <input name="BIRTHDAY" type="text" pattern="(0[1-9]|1[0-9]|2[0-9]|3[01])\/(0[1-9]|1[012])" />
    <input class="birthday REQ_CSS" type="text" pattern="(0[1-9]|1[0-9]|2[0-9]|3[01])" placeholder="Giorno" size="2" maxlength="2" name="BIRTHDAY[day]" id="mce-BIRTHDAY-day" value="">
    
    <input class="birthday REQ_CSS" type="text" pattern="(0[1-9]|1[012])" placeholder="Mese" size="2" maxlength="2" name="BIRTHDAY[month]" id="mce-BIRTHDAY-month" value="">

    but I always get 01/01. What am I doing wrong?
    Thank you in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Lap

    (@lapzor)

    I think the first two examples should be working.

    Do you get 01/01 on your own tests as well, or you just see that a lot of subscriptions come in with that, but it works properly when you test it yourself?

    Thread Starter lucari

    (@lucari)

    @lapzor thanks for your reply.
    Unluckily, I get 01/01 with my own tests too.

    About the third example with two text inputs, I took the code from a custom HTML form generated in my Mailchimp account (Audience > Forms > Form Builder)
    The weird thing is that, if I try to embed this official HTML form, all the data is gathered properly, birthdays too. But I don’t want to keep the official form since it redirects users after subscription or errors, while MC4WP form works seamlessy.

    Plugin Contributor Lap

    (@lapzor)

    copying any code from the embedded MC form into our form builder will not work. Please always add the fields with the buttons above the form builder in our plugin.

    If you add this field with the form builder button, is the name still “BIRTHDAY” or does it get another name? Or does the field not show up at all in the form builder?

    Thanks for letting me know.

    Thread Starter lucari

    (@lucari)

    @lapzor thank you for your availability!

    If I add the “Birthday” text input with MC4WP form builder button, the name is still “BIRTHDAY”. I tested it and it actually works, if the user writes their birthday in the DD/MM format, otherwise it returns 01/01.

    Because of this, I wanted to find a smart solution to avoid any user error (i.e. somebody could write MM/DD, somebody else could use dashes or dots instead of slashes, some other could write the name of the month… ) which would all return an incorrect date.

    I just came out with this solution:
    1 – the users inserts their birthday via a date input so that I am sure that it is set in the very same way for everyone; the input has no specific name;
    2 – Javascript converts the date input value to DD/MM and sends to a hidden field named “BIRTHDAY”
    3 – the date/text from “BIRTHDAY” hidden input is sent to MailChimp.

    This is the code I added: it might be better since I am not a programmer, but I tested it and it works fine!

      <input type="date" onchange="myDateFormat()" required="">
      <input type="hidden" id="showDate" name="BIRTHDAY">
    
      <script type="text/javascript">
        function myDateFormat() {
          var dateControl = document.querySelector('input[type="date"]');
          const [year, month, day] =       dateControl.value.split('-');
          const result = [day, month].join('/');
          document.getElementById("showDate").value = result;
    
        }
    
      </script>


    Plugin Contributor Lap

    (@lapzor)

    Using the type=”date” field would allow someone to put the date in their browser language format, and always output yyyy/mm/dd to Mailchimp, but this field includes year as well.

    Otherwise you indeed need to use some third party date picker to deal with the date format, or write your own code as you did.

    Another way I can think of would be using select fields, but this as well would need some extra code to combine the selected values into a hidden field before sending it to Mailchimp.

    Kind regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Birthday date in form’ is closed to new replies.