2

I have a web to lead salesforce form, and I want to have a dynamic thank you page link based on the answers I get in the form. I was trying to do it like so by setting the retUrl var in the salesforce servlet url with javascript.

<form id="salesforce_form" action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
.....
</form>
<script type="text/javascript">
  function submitForm() {
    var form = document.getElementById("salesforce_form");
    var score = get_score(); //returns a number
    form.action += "&retUrl=https://www.fakesite.com/thanks?score=" + score;
    return true;
  }
</script>

I was thinking I could send it to the same url just adding a url param, but it seems to be ingnored when I send the form to salesforce.

2

As it turns out there is a hidden form field for the return URL. I just edited that.

<input id="returl" type=hidden name="retURL" value="https://www.fakesite.com/">
....
<button type="submit" name="submit" onClick="submitForm()">Submit</button>
function submitForm() {
  var form = document.getElementById("salesforce_form");
  var score = get_score(); //returns a number
  var returl = document.getElementById("returl");
  returl.value += "thanks/?score=" + score;
  return true;  // return false to not submit the form
}

Also in this case returning true just submits the form, and avoids overriding the normal submit form behavior, by returning false you could do something else. This was unclear in my original question.

1

There's a hidden field already on your Web-to-Lead form when you generate it from Salesforce, so you can change that field as required.

<input type=hidden name="retURL" value="whatever you provide">

But if you want it to be more dynamic, here's how you can do this.

  1. Remove the hidden field from the form
  2. Have the return URL specified exactly as it was is in the generated form (case sensitive). So it should be retURL.
  3. You will need to submit the form from your JS function.

function submitForm() {
    var form = document.getElementById("salesforce_form");
    form.action += "&retURL=<your URL>"; // notice the case
    form.submit(); // submit the form
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.