I am attempting to make my SalesForce form work with a redesigned form using AJAX instead of a simple jQuery submit function. I don't understand what I am doing wrong. Right now after submitting the form, the page redirects to the salesforce link https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8.

Data is not being inserted into salesforce either.

Within the form itself, I have left all of the inputs with their correct id's, left the action to the salesforce WebToLead link, and method as post. The only thing different is that I have made this an AJAX call, but within my complete function I put in the $("#salesforce_submit").submit();, which this was previously submitting the form.

Does anyone see what I am doing wrong and why this is not working?


    <form action="https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" id="salesforce_submit" method="POST" enctype="multipart/form-data">
        <input name="oid" type="hidden" value="realId"><input type="hidden" id="realId" id="interestValue" multiple="multiple" name="realId" value=""><input name="retURL" type="hidden"> <input name="lead_source" required="" type="hidden" value="Quote Form"> <input id="txt_medium" name="txt_medium" type="hidden" value=""> <input id="txt_source" name="txt_source" type="hidden" value=""> <input id="txt_campaign_name" name="txt_campaign_name" type="hidden" value=""> <input id="txt_term" name="txt_term" type="hidden" value=""> <input id="txt_content" name="txt_content" type="hidden" value="">
            <div><input id="first_name" placeholder="First Name*" class="input block" maxlength="40" name="first_name" type="text"></div>
            <button type="submit" class="bigButtonLink bigButton">


    ignore: [],
    rules: {
        first_name: {
            required: true,
            minlength: 2
    messages: {
        first_name: {
            required: "Please enter your first name",
            minlength: "Your first name seems a bit short, doesn't it?"
    submitHandler: function(form) {
        var datastring = $('#salesforce_submit').serialize();
            url: '/php/quoteSend.php',
            type: 'POST',
            data: datastring
            success: function(data) {
                if (data == 'Error!') {
                    alert('Unable to submit form!');
                } else {
            complete: function() {
                //location.href = "";
            error: function(xhr, textStatus, errorThrown) {
                alert(textStatus + '|' + errorThrown);

In the submitHandler function...

 url: '/php/quoteSend.php' 

should be

url: 'https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8'

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.