Birthday Field With No Year

Dan_Askin
Level 4

Birthday Field With No Year

Assume the answer -- at least one answer -- is to create two integer fields and add some instructive text/egs/code on the form to show/force how to correctly fill in the fields, but. Mailchimp, for example, has a birthday field type.

Also, trying to wrap my head around how you'd automate a birthday message if you have two custom fields.

Thanks,

Dan

3 REPLIES 3
Jay_Jiang
Level 10

Re: Birthday Field With No Year

If ultimately you just want to email people on their birthday, you can try using advanced wait + date token + next anniversary. Have 2 campaigns requesting each other so it becomes perpetual (a campaign can't request itself). To start someone off on the emails you may use a Data value changes trigger and Date of Birth is not empty.

pastedImage_0.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Birthday Field With No Year

Jay outlines perfectly why the Date datatype has special power in Marketo that you wouldn't be able to replicate any other way.

If what you're actually trying to do is offer somebody a friendly form (where they don't feel the intrusion of telling you their age ) you can do that by using 2 auxiliary fields on the form.

Technically, as you know from past work, you don't even need to create those fields in Marketo, but for simplicity's sake let's assume you have the 2 custom Integer fields MonthofBirth and DayofBirth in Marketo and on the form (as dropdowns or text fields or whatever).

Then in onSubmit, assemble the DateofBirth as a hidden field, with year 1000 as a placeholder:

MktoForms2.whenReady(function(form){ 

   form.onSubmit(function(form){

      var currentValues = form.getValues();

     

      form.addHiddenFields({

         DateofBirth :

            ["1000"]

            .concat(

               ["MonthofBirth","DayofBirth"]

               .map(function leftPad(field){

                 return ("0" + currentValues[field]).slice(-2);

              })

            )

           .join("-")

      });

   });

});

This allows you to use the usual anniversary logic as the field is stored as a Date.

Dan_Askin
Level 4

Re: Birthday Field With No Year

You got it, Sanford -- politeness is where it's at. Good call on the hidden field attribute/aux fields approach. Appreciate the insight.