[SalesForce] How to disable redirect after submitting web-to-lead form

I've integrated the web-to-lead code (created from the salesforce ui) into a popup on a wordpress website.

My ideal flow is as follows:

  1. User opens the popup and fills in the web-to-lead form.
  2. User presses submit and a new lead gets created on the associated salesforce account.
  3. On the same popup, the user receives a success message.
  4. User will close the popup and continue on his merry way.

What's actually happening:

  • After the user presses the submit button, the page redirect occurs. Even if the url is the same url he/she is currently on, the page will refresh and the popup closes automatically. There's no chance for the success message to be displayed.

My code:

<form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" target="_self">
  <input type=hidden name="oid" value="XXXXXXXXXXXX">
  <label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
  <label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
  <label for="email">Email</label><input id="email" maxlength="80" name="email" size="20" type="text" /><br>
  <label for="company">Company</label><input id="company" maxlength="40" name="company" size="20" type="text" /><br>
  <label for="phone">Phone</label><input id="phone" maxlength="40" name="phone" size="20" type="text" /><br>
  <input type="submit" name="submit">
</form>

Originally, I also had <input type=hidden name="retURL" value="https://mywebsite"> . However I removed it in hopes that the redirect wouldn't occur. Sadly, the redirect still occured.

Best Answer

The reason it is behaving as it is because web-to-lead code is embedded into the page source (as in inlined with main page source). Since that form is submitted, browser is going to treat as main page submission.

You can do two things.

  1. Change the return url in Salesforce config to include a variable. For ex., https://www.example.com/contact?success=true. Then in the on page load, if that variable is there, then show the thank you or success message.

  2. Load the web to lead in popup with iframe. Then when submission happens, iframe is submitted. Then you can display a message to user.

Related Topic