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

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

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

Post 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
Last edited by blackhawk on Mon Jul 15, 2013 5:48 pm, edited 4 times in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post by calguy1000 »

you could use the forms action attribute.
and add ?showtemplate=false to it.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

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

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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.
});
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

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

Post by blackhawk »

Works like a charm. Thank you Calguy!
Post Reply

Return to “The Lounge”