WordPress.org

Ready to get started?Download WordPress

Forums

WordPress-to-lead for Salesforce CRM
AJAX Submission? (6 posts)

  1. devinmcinnis
    Member
    Posted 11 months ago #

    Is there a way to implement an AJAX submission where I don't have to refresh the page? I can't seem to find anything built in and I'd rather not manually edit the files because it will probably conflict when the plug-in receives an upgrade.

    Thank you.

    http://wordpress.org/extend/plugins/salesforce-wordpress-to-lead/

  2. Nick Ciske
    Member
    Plugin Author

    Posted 11 months ago #

    You could short circuit the form submit with jQuery and submit the data to the Salesforce API yourself via ajax (without touching the core plugin), but it would require some decent coding chops to pull off.

  3. devinmcinnis
    Member
    Posted 11 months ago #

    Yeah, I thought about that but couldn't think of a way to do it without exposing the Organization's ID and still be able to work with the plug-in's settings.

    Thanks anyway, Nick.

  4. Nick Ciske
    Member
    Plugin Author

    Posted 11 months ago #

    You could call your own AJAX function in WordPress and access that data from the WP options.

    It's a workaround, but if you sent me the code, I may be able to adapt it into a future version.

    Or, feel free to fork it on GitHub and submit a pull request with Ajax baked in ;-)
    https://github.com/nciske/salesforce-wordpress-to-lead

  5. devinmcinnis
    Member
    Posted 11 months ago #

    I've solved this with a simple jQuery POST function:

    $('form').submit(function(){
      var email = $(this).find('#sf_email');
    
      $.post('/halcyon/',
        {
          // These are the fields you are sending
          email: email.val(),
    
          // Note: these fields are required to validate for Salesforce
          message: '',
          form_id:1,
          successmsg:1,
          errormsg:1,
          w2lsubmit:'Join'
        },
        function(data, status, jqXHR){
          // Do something to notify user data has been sent
          email.val('');
          console.log(status + ' with status code: ' + jqXHR.status);
        }
      )
      .fail(function(){
        console.log('Oh no! We have failed you.');
      });
    
      // Stop page from refreshing
      return false;
    });

    Edit: The only problem I've found with this is that is always returns "success" so you will have to validate the form on the client-side before sending. If you want, I could set up a pull request to add type="email" instead of having emails as plain text because SF won't throw errors.

  6. Nick Ciske
    Member
    Plugin Author

    Posted 11 months ago #

    Yeah, the Web 2 Lead API is weird like that -- if I remember right it returns an HTTP header/code instead of a message in the body (you can view the plugin code to see how it's handled there).

    How are you passing the organization ID here?

Reply

You must log in to post.

About this Plugin

About this Topic