SOLVED

Null field value if no value is given on form submit

Go to solution
Christina_Dearm
Level 2

Null field value if no value is given on form submit

We are trying to set up a process where if a person submits a form, and a non-required field is left empty, we infer that means the person no longer has that item.

Example: Bill told us 4 years ago he grows Rice. This year he renews his subscription to our magazine and leaves Rice blank (we cannot pre-fill per print audit rules). We want to have Marketo wipe out his previous answer and assume he no longer grows rice.

Can that be accomplished?

I thought perhaps have some sort of trigger campaign but that will overload our system and create a log jam in our Campaign Queue.

Ideas?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Null field value if no value is given on form submit

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Null field value if no value is given on form submit

Grégoire_Miche2
Level 10

Re: Null field value if no value is given on form submit

Hi Sanford Whiteman​,

I have read the blog article and have a question: why adding a null value to the fields in the form. Why not simply capturing the fact that the form fields are empty and set a NULL value ?

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Null field value if no value is given on form submit

Because not every field is expected to turn no answer → NULL.

The same could be done with a configuration block at the top of the JS, but I opted to not do that in this case.

Grégoire_Miche2
Level 10

Re: Null field value if no value is given on form submit

OK,

It's just a way to detect which fields should be processed that way. So a class in the label would also do the trick. Or a conf field by a token and containing the list of data-wrapper-for tag attributes ?

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Null field value if no value is given on form submit

Right, I would use an array of field names if going with the conf block.

Grégoire_Miche2
Level 10

Re: Null field value if no value is given on form submit

Here is my code, using an array, but the NULL does not post to the database

Page : placo

result:

pastedImage_4.png

and the field remains unchanged...

Any idea bout a bug I might have introduced?

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Null field value if no value is given on form submit

Ha! Now I remember (stupid to forget) the other reason I add the "NULL" as an actual value: you can't setValues() on an enum field (checkboxes, select, radio) unless the value exists as part of the enumeration.

Also, be careful to not use Array#includes, Object.entries, or Object.values on public sites yet as they don't work in IE.

And I'd probably have done the iteration like this:

Object.keys(currentVals)

.filter(function(field){

  return ( NullifiableFieldNames.indexOf(field) != -1 && currentVals[field] );

})

.forEach(function(field){

  newFormData[field] = "NULL";

});

Grégoire_Miche2
Level 10

Re: Null field value if no value is given on form submit

you can't setValues() on an enum field (checkboxes, select, radio) unless the value exists as part of the enumeration

So I guess then the best way to set this up is to select all the fields that have a NULL in the enumeration as you did in the blog post and drop the idea of designating the fields through an array.

Thx so much!

-Greg

Grégoire_Miche2
Level 10

Re: Null field value if no value is given on form submit

Hi again Sanford Whiteman​,

Also, be careful to not use Array#includes, Object.entries, or Object.values on public sites yet as they don't work in IE.

How do I test the existence of a field in the form ?

-Greg