SOLVED

Re: Field Calculations

Go to solution
Bonni_Graham_Go
Level 2

Re: Field Calculations

And this is why I don't program for a living. I am SO BAD at catching these. Once more into the breach!

Bonni_Graham_Go
Level 2

Re: Field Calculations

I've done that, but now it's showing the form twice - once from the wordpress widget call, and once from this script. How do I get it to show the form only once? Is it as simple as removing this code? 

 

 

MktoForms2.loadForm(mktoInstance, munchkinId, formId,
   function (form)

 

I'm honestly feeling like the stupidest person in the world right now.

SanfordWhiteman
Level 10 - Community Moderator

Re: Field Calculations

Yes, because you're already loading the form, you don't want to use the onReady argument to loadForm, but rather a separate whenReady.

 

var fieldProxyForWhatDevices = 'QuizWhatDevices';
var fieldProxyForDeviceHardening = 'QuizDeviceHardening';
var fieldProxyForResponsePlan = 'QuizResponsePlan';
var fieldProxyForThreats = 'QuizThreats';
var fieldProxyForImpact = 'QuizImpact';
var fieldProxyForScore = 'QuizTotalScore';

MktoForms2.whenReady(function (form){
  form.onSubmit(function (form){
    var currentValues = form.getValues();

    var devices = +currentValues[fieldProxyForWhatDevices];
    var hardening = +currentValues[fieldProxyForDeviceHardening];
    var response = +currentValues[fieldProxyForResponsePlan];
    var threats = +currentValues[fieldProxyForThreats];
    var impact = +currentValues[fieldProxyForImpact];

    var finalValues = {};
    // calc the actual final value and post that to Marketo
    finalValues[fieldProxyForScore] = devices + hardening + response + threats + impact;
    form.setValues(finalValues);
  });
});

 

Not sure why you had a form.submittable(false) in there, that would make the form never submit.

Bonni_Graham_Go
Level 2

Re: Field Calculations

Thanks. Trying that. The form.submittable(false) was in the original sample and I wasn't sure whether it was important.