How to force Marketo to accept a *blank* field

Highlighted
Level 2

How to force Marketo to accept a *blank* field

Hi, I have a very simple Marketo form where someone fills out (amongst other things) their address.

We use Address Line 1, 2 & 3 rather than the 'Address' field.

On the form, Add 1 & 2 are compulsory fields and 3 is not.

In the following example, someone fills out the form, who is already on the database and has changed address

PREVIOUS VALUES FILLED IN ON FORM

Address Line 1 1 The High Street 21 Harbour Road

Address Line 2 Botley Portsmouth

Address Line 3 Southampton *this field is left blank*

As Marketo will not overwrite actual data with a blank, how can I make sure that Address Line 3 does not stay "Southampton" and becomes a blank?

1 REPLY 1
Highlighted
Level 10 - Community Moderator

Re: How to force Marketo to accept a *blank* field

An excellent question and one that isn't asked enough IMO (that is, people don't understand how the default behavior affects their data health).

A deep explanation is at Clearing lead fields based on unanswered form questions​.

For the case of a text field, use this custom Forms JS code, listing your fields in the emptyToNull array.

MktoForms2.whenReady(function(form) {

var userConfig = {

emptyToNull: ["AddressLine2", "AddressLine3"]

};

/* --- No need to edit below this line! --- */

var formEl = form.getFormElem()[0];

form.onSubmit(function(form) {

var currentValues = form.getValues(),

mktoFieldsObj = {};

Object.keys(currentValues)

.filter(function(fieldName) {

return (

currentValues[fieldName] == "" &&

userConfig.emptyToNull.indexOf(fieldName) != -1

);

})

.forEach(function(fieldName) {

mktoFieldsObj[fieldName] = "NULL";

formEl.querySelector("[name='" + fieldName + "']").style.color = "transparent";

});

form.setValues(mktoFieldsObj);

});

});