SOLVED

Re: Using lead form values to dictate form field visibility rules

Go to solution
Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Sorry, updated! So it looks like the below..but still isnt working. Is there anything in the page source code that is interfering with the JS?

pastedImage_2.png

Jay_Jiang
Level 10

Re: Using lead form values to dictate form field visibility rules

Keep the isAgency as a checkbox (boolean) and then apply the following visibility rule to the checkbox you want to hide and add the script to the landing page after the form element.

pastedImage_1.png

Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Thank you, I got it to work but still have some questions.

1. Using just the checkbox approach would move the value to true in our Marketo database if it is selected, and false if it is not, correct? The issue with that is when it does show up, I want it to be a required field. So if it shows up with one checkbox, then the person would be required to answer yes and check it..even if they answer for them would be no, right? Is there a way to implement with checkboxes? That way when it is required and does show up, someone can select yes or a no option.

2. I still want this field to show up if someone has not answered the agency question previously ( aka a new lead)..so if there is a null value indicating that the user has not answered yes or no to the agency question previously then they would be showed this question. If they had answered it previously then they would not see it.

   - I tested this by using private mode so that my cookies are not tracked, and the form still hid the field. If this would work how i wanted it would show the field to a new user without a cookie indicating they answered this question already.

https://build.amazonalexadev.com/Youtube-Integration_DynamicTest.html  For example if this is hidden for you when you click on it, then it is not working how I intended because you would have not answered this previously. Would i change the rules below to "Show" if isagencydynamic is "null"?

Let me know if this is possible and or if I am missing another small detail to make this happen. Thank you both!

pastedImage_2.png

Jay_Jiang
Level 10

Re: Using lead form values to dictate form field visibility rules

I was under the impression you wanted a single checkbox (boolean) according to your opening post.

But yes you can customise it how ever you want. You're actually no longer limited to "yes" or "no" if you're database field is a string field and your front end is not a single checkbox (boolean).

So you can go back to using True/False or Yes/No and checkboxes, but logically wouldn't you use radio buttons?

You could even just use the visibility rule Hide IsAgency if dynamicfield "is not empty"

I still want this field to show up if someone has not answered the agency question previously

But I'd like to add that your whole solution requires pre-fill to work, which will require some additional workarounds...

Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Thanks, I changed it to "is empty". You are absolutely right about radio buttons as the logical choice.

What additional workarounds would be necessary? I have form prefilled enabled for both fields, are you saying there is additional JS needed to append the value we have in the database to the hidden field?

pastedImage_1.png

Jay_Jiang
Level 10

Re: Using lead form values to dictate form field visibility rules

Form pre-fill is limited to immediate click through from an email link at the moment unless you implement either Sanford's workaround or my workaround.

Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Thanks- I implemented your solution. Since I really only need to get the hidden field ( isagencydynamic) pre-filled to get the is agency visibility rules to work i just used a shortened version below. Would this work? Or should i remove Sanford's code that I had originally put to getvalues?

<script>
MktoForms2.whenReady(function (form) {
var init_fields = {
"Isagencydynamic":"{{lead.isagency}}",
}});
</script>
<script>
MktoForms2.whenReady(function(form){
form.setValues({
isAgencyDynamic : form.getValues().isAgency
});
}) ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
</script>

This code is live on: https://build.amazonalexadev.com/Youtube-Integration_DynamicTest.html  and still not working, so obviously still doing something wrong.

Thanks!

Jay_Jiang
Level 10

Re: Using lead form values to dictate form field visibility rules

try this:

MktoForms2.whenReady(function (form) {
var init_fields = {
"isAgencyDynamic":"{{lead.Is Agency}}", // whatever your Marketo token is supposed to be
}
form.vals(init_fields);
});
Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Thank you! Confirming this works.