Remove Form Pre-Fill on a Single Field (Dynamically if Possible)

Justin_Norris1
Level 10 - Champion Alumni

Remove Form Pre-Fill on a Single Field (Dynamically if Possible)

Hi all,

Form pre-fill is great but sometimes it creates problem.

Example: if you populate known records that have an empty last name or company name field with "[not provided]" or some other default value in order to ensure those records still sync to SFDC...

...Then when those known leads go to fill out another form they see a weird "[not provided]" value pre-filling in their forms.

I'm wondering if anyone knows a trick to do one of the following (in descending order of preference):

1) Dynamically suppress the pre-fill: in an ideal world, have some logic that could be added to an individual form that says, "if company name = [not provided], clear pre-fill for that field". I am assuming this would probably need to be done with some extra javascript.

2) Turn of pre-fill for one field: lacking a more intelligent method like above, we could also turn off pre-fill entirely but just for that one field, so that we don't lose the benefit of other fields.

Love to know if anyone has solved for this.

Thanks!

Tags (2)
5 REPLIES 5
Elliott_Lowe1
Level 9 - Champion Alumni

Re: Remove Form Pre-Fill on a Single Field (Dynamically if Possible)

You could create a parallel field to use in the form.  You'd have a smart campaign that would copy the value from the Last Name field into the Last Name (form only) field, but not if the value in the Last Name field is '[not provided]', 'N/A', etc.  Then the form prefill would be blank in that field in the form.  If they enter a value in the field, your smart campaign would copy the value into the Last Name field and overwrite '[not provided]'.

SanfordWhiteman
Level 10 - Community Moderator

Re: Remove Form Pre-Fill on a Single Field (Dynamically if Possible)

MktoForms2.whenReady(function(form) {

   var treatAsBlank = [
   'N/A',
   'Not Provided',
   '[Not Provided]',
   'null'
  ],
   treatAsBlankRE = new RegExp('^(' + treatAsBlank.join('|') + ')$', 'i');

   if (treatAsBlankRE.test(form.getValues().FirstName)) {
   form.setValues({
   FirstName: ''
  });
  }

});

Justin_Norris1
Level 10 - Champion Alumni

Re: Remove Form Pre-Fill on a Single Field (Dynamically if Possible)

Sanford Whiteman

Sandy, I've been trying to deploy this but doesn't seem to be working. Any thoughts on what I'm doing wrong?

Here is the test page: http://na-sj09.marketo.com/lp/559-LNN-604/Justin-Testing-Program_Testing-Pre-Fill-Remove.html

And here is the code I'm using -- I modified it in this example to include two If statements for two fields that both use [Not Provided], but I tried it with one field and with equal lack of success. Also I am including this in an HTML element via the landing page editor, in case that matters.

<script>

MktoForms2.whenReady(function(form) {

  var treatAsBlank = [

  'N/A',

  'Not Provided',

  '[Not Provided]',

  'null'

  ],

  treatAsBlankRE = new RegExp('^(' + treatAsBlank.join('|') + ')$', 'i');

  if (treatAsBlankRE.test(form.getValues().LastName)) {

  form.setValues({

  LastName: ''

  });

  }

if (treatAsBlankRE.test(form.getValues().Company)) {

  form.setValues({

  Company: ''

  });

  }

});

</script>

SanfordWhiteman
Level 10 - Community Moderator

Re: Remove Form Pre-Fill on a Single Field (Dynamically if Possible)

It actually does look like it's working for me: I created a lead with Last Name 'N/A' and submitted the form.  Then when I refreshed it to prefill, it blanked out the Last Name (although I could see that the server had returned the saved last name to the form, the whenReady code blanked out the input box).

Justin_Norris1
Level 10 - Champion Alumni

Re: Remove Form Pre-Fill on a Single Field (Dynamically if Possible)

Elliott Lowe​ very clever way of doing it without any code! So many uses to parallel fields.

Sanford Whiteman​, I had a feeling you would have a fancy JS method up your sleeve

Thanks a lot guys. Both solutions would do the job.