Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-03-25 18:12:39

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Zem_Contact_Reborn submitting with AJAX

As I suggested here, I’d like to figure out how to submit Zem_Contact_Reborn with Jquery AJAX.

Here are the resources I’m using: jquery and jquery form plugin
Here’s what I have so far, and its not much, mostly just a cut and paste.

<script type="text/javascript" src="path/to/jquery.js"></script> 
<script type="text/javascript" src="path/to/form.js"></script> 

   <script type="text/javascript"> 
        // wait for the DOM to be loaded 
        $(document).ready(function() { 
            // bind 'zemContactForm' and provide a simple callback function 
            $('form.zemContactForm').ajaxForm(function() { 
                alert("Thank you for your comment!"); 
            }); 
        }); 
    </script>

Of course, this only gives me a dumb js alert. I want to do the following:

  • Do some form validation along the way
  • Pull in the thanks form (in presentation/forms/) after submission
  • Clear and Reset the form

The code samples page shows the implementation of a lot of these things, but I could use some direction, as I’m not sure I understand what goes where etc.

Helpy helperton?

Matthew

Last edited by ma_smith (2007-03-26 09:21:27)


Offline

#2 2007-03-26 09:22:31

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: Zem_Contact_Reborn submitting with AJAX

Okay, clearly one issue here is that the id of the form is generated by the plugin and is a large string of alphanumeric characters like this (zcrf63b659e09d62cc772486b6ffafc9d00). Does anyone have any suggestions about how the JS might interract with this id? Or if it needs to?


Offline

#3 2007-03-26 14:19:25

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

Re: Zem_Contact_Reborn submitting with AJAX

If you are using jQuery you shouldn’t need the id $('form.zemContactForm') is effectively the same thing as $('#zcrf63b659e09d62cc772486b6ffafc9d00').

Using the id might be a little faster.


Shoving is the answer – pusher robot

Offline

#4 2007-03-26 16:39:05

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: Zem_Contact_Reborn submitting with AJAX

Okay, sounds good Patrick. I think I get that. :)

Here’s what I’m working with at the moment:

<script type="text/javascript">
	// prepare the form when the DOM is ready 
	$(document).ready(function() { 
	    // bind form using ajaxForm 
	    $('form.zemContactForm').ajaxForm({ 
	        success: function() { 
	            $('#zemThanks'); 
	        } 
	    }); 
	});
	</script>

This submits .zemContactForm, but does not display a thanks form, nor (as I would have expected) does it show any validation errors. What’s the first step to getting the server data from the thanks form to show up? I tried changing the $('#zemThanks'); to the broader div $('#contact > .left > .post');, thinking that it might not be finding #zemThanks to display the information. but nope :)

Since, I am under some pressure to finish this, if anyone has a moment (including you patrick), to work this out with me within a weeks time or so, I’d glady contribute to someone’s amazon wishlist, or a threadless tshirt or some such :).

CHeerio. M

Last edited by ma_smith (2007-03-26 17:17:28)


Offline

#5 2007-03-26 18:39:48

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

Re: Zem_Contact_Reborn submitting with AJAX

Try this to start

<script type="text/javascript">
	// prepare the form when the DOM is ready 
	$(document).ready(function() { 
	    // bind form using ajaxForm 
	    $('form.zemContactForm').ajaxForm({ 
                  target :'#zemThanks',
	        success: function(responseText, statusText) {
                    alert(responseText);
	        } 
	    }); 
	});
	</script>

it should update #zemThanks but if it doesn’t it should alert what is coming back. My fear is that you are getting a full html page back so you might have to parse through it.


Shoving is the answer – pusher robot

Offline

#6 2007-03-26 18:49:56

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: Zem_Contact_Reborn submitting with AJAX

Hak,
Thx. I got this error in firebug:

jQuery(options.target).attr("innerHTML", data).evalScripts is not a function
(no name)("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\r\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-s...", "success")jquery.form.js (line 220)
success("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"\r\n "http://www.w3.org/TR/xhtml1/DTD/xhtml1-s...", "success")jquery.form.js (line 228)
e(undefined)jquery.js (line 12)
[Break on this error] jQuery(options.target).attr("innerHTML", data).evalScripts().each(ol...

I tried to understand what that’s saying, but I’m at a loss.

EDIT by the way, the form submitted, but no returned info from the server.

:)

Matthew

Last edited by ma_smith (2007-03-26 18:54:44)


Offline

#7 2007-06-27 11:21:31

Joey
Member
From: Netherlands
Registered: 2005-01-19
Posts: 257

Re: Zem_Contact_Reborn submitting with AJAX

Matthew, did you came any further with this in the meantime? I’d love to see this option in zem_contact_reborn. I know almost nothing about Javascript and jQuery, however I would like to learn jQuery better so maybe I could help. I’ll will take a look at it in a few weeks when I finished school.

Last edited by Joey (2007-06-27 11:21:47)


Regards,

Joey

Offline

#8 2007-06-27 14:22:00

squaredeye
Member
From: Greenville, SC
Registered: 2005-07-31
Posts: 1,495
Website

Re: Zem_Contact_Reborn submitting with AJAX

Joey,
I did get this mostly working. Pretty nicely really. I will be launching the site I’m using it with shortly (If I keep saying that, eventually no one will believe me), and I have a near finished tutorial on the subject as well.

Matthew


Offline

#9 2007-06-27 14:35:51

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

Re: Zem_Contact_Reborn submitting with AJAX

We did get it working. It took a few minor changes to ZCR. I owe Matthew a write up on the changes.


Shoving is the answer – pusher robot

Offline

#10 2007-06-27 16:29:27

Joey
Member
From: Netherlands
Registered: 2005-01-19
Posts: 257

Re: Zem_Contact_Reborn submitting with AJAX

Great! Can’t wait to see it working. Thanks for the efforts! :-) Is it going to be build in in ZCR?

Last edited by Joey (2007-06-27 16:32:29)


Regards,

Joey

Offline

#11 2007-06-28 14:08:25

hakjoon
Member
From: Arlington, VA
Registered: 2004-07-29
Posts: 1,634
Website

Re: Zem_Contact_Reborn submitting with AJAX

What we ended up building was more of a hack then an implementation, but it works. I think a more elegant solution could be worked out with some reworking of ZCR.


Shoving is the answer – pusher robot

Offline

#12 2008-08-28 21:47:23

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Zem_Contact_Reborn submitting with AJAX

I’d like to implement this as well but seems matthew’s site is down so the tutorial is unavaliable.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

Board footer

Powered by FluxBB