Page 1 of 1

[SOLVED] Extending Form Builder with AJAX-submit() Handling

Posted: Mon Jul 15, 2013 11:05 am
by blackhawk
I'm using cmsms 1.11.7 and I am trying to use AJAX on top of Form Builder 0.7.3.

I created a test page outside of cmsms with an AJAX request. The code on my test page looks like this...

Code: Select all

var fcontactform = $('.contact-form');

fcontactform.submit(function() {
//..some jquery logic...

  $.post("pear/index.php", fcontactform.serialize(), function(data){         
    //...now show jquery confirmation message...thank you...
  });
return false;
}
'pear/index.php', being the place where all my form data is processed, and then sent with php mail functions. But I think I don't need to worry about using 'pear/index.php' because formbuilder has it's own processing page location.

So my question boils down to this...How do I adjust my $post() tag above, to connect to the right file so that formbuilder sends data?

Thanks for any advice, even if there is better way to submit via AJAX with Form Builder!

bh

Re: Extending Form Builder with AJAX - submit() Handling

Posted: Mon Jul 15, 2013 4:43 pm
by calguy1000
you could use the forms action attribute.
and add ?showtemplate=false to it.

Re: Extending Form Builder with AJAX - submit() Handling

Posted: Mon Jul 15, 2013 4:59 pm
by blackhawk
Thank you Calguy!
Sorry for the additional quesiton, but when you say the 'form's action attribute', you mean for me to literally look at my DOM when the page loads and copy the action attribute URL that appears in my console window, and put that into my post method?


I have pretty URL's enabled (I think..) and when I do look at the code, my action attribute looks like this...

action=http://dev.klp/

this is virtual location on my localhost - just FYI


thanks

Re: Extending Form Builder with AJAX - submit() Handling

Posted: Mon Jul 15, 2013 5:10 pm
by calguy1000
That's because your form is on the homepage of your cmsms website.
so what you want to do is simulate exactly what CMSMS would do when submitting the form, without doing all the redirect cruft. this should do it.

$('#myform').submit(function(){
var url = $(this).attr('action')+'?showtemplate=false'; // pretty urls... may need some intelligence here.
var data = $(this).serialize();
$.post(url,data,function(data,textStatus,jqXHR){
alert('post came back');
});
return false; // prevent any default stuff from happening.
});

Re: Extending Form Builder with AJAX - submit() Handling

Posted: Mon Jul 15, 2013 5:48 pm
by blackhawk
Works like a charm. Thank you Calguy!