AJAX Plugin - NEED HELP!! :-)
Posted: 06 February 2008 08:07 AM   [ Ignore ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6573
Joined  04-15-2006

Hiya,

I was just wondering if someone could help me with a little something.

I am currently trying to create a plugin that will wrap around a form and using AJAX will check certain things on the fly. I am pretty sure I have all the AJAX code sorted and can get this to work if it is hard-coded into the page but not too sure how I would go about getting this into a plugin which gets called when someone types in a field?

At the moment let’s take an example (don’t want to give too much away now!! grin ).

Let’s say I have a simple form with a text field for ‘Type of animal’ in it.
I now have some very simple javascript in the head of the html page that basically says when the user has finished typing into this field and tabs out of the field then call a file called animals.php. This PHP file would then do some checks and if the person has placed in a correct answer such as cat then it would return a piece of text to the same page informing the user that they have made a valid choice. This would then allow them to submit the form.

If on the other hand they placed say the word car into the field then the animals.php file would throw back an error message instead and would not allow the form to be submitted.

As I said before I am pretty sure that I can get all of this working except for the stopping the form submitting even if they do put in a wrong answer but I have no idea how I would place all of this into a plugin that can be wrapped around a form?

What I would like to end up with is something like this :

{exp:check_animal}

<fieldset>
<
legend>Animal Form</legend>
<
form action="index.html" method="post">
<
p><label for="animal">Type Of Animal:</label>
<
input type="text" name="animal" id="animal" />
<
span id="animal-loading"><img src="loading.gif" alt="Ajax Loading Icon" /></span>
<
span id="result"></span></p>
<
p><input type="submit" name="submit" value="Check Animal Type" /></p>
</
form>
</
fieldset>

{/exp:check_animal}

So basically the plugin could effectively wrap around any sort of form and then the rest would be as I can code it into a normal html page. Really not sure where to start with this one as I will need a tag which will go into the head of the document for the Javascript dependencies and then some way of calling the PHP file etc…

Any help with this would be greatly appreciated.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 06 February 2008 08:48 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  537
Joined  02-25-2003

You can start by looking at Mootools. They have a pretty good set of AJAX scripts built into their app:
http://demos.mootools.net/Element.Event

Profile
 
 
Posted: 06 February 2008 09:00 AM   [ Ignore ]   [ # 2 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6573
Joined  04-15-2006

Hiya dombi,

Thanks for the link but I do actually already have a script that I have written that will do what I need. What I would like to do though is to take out all the extra code that I have now put into my template and just utilise it from a plugin instead.

Any help from anyone on that would be greatly appreciated.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 07 February 2008 06:06 PM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6573
Joined  04-15-2006

Hiya,

Sorry to do the very shameful act of bumping this post up but if anyone has any ideas as to what I am trying to do and can help me out I would be very grateful thanks.

Basically what I am trying to do is take some existing AJAX code that I have written around a form and place it into a plugin so that I can re-use it more easily. I’m not entirely sure if this is even possible though as I am now wondering can you even call a plugin in that way continually or can it only be called once when the template is rendered?

Thanks for any help with this.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 09 February 2008 04:50 PM   [ Ignore ]   [ # 4 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6573
Joined  04-15-2006

I’ve decided to give up on this one as I don’t think that what I would like to do is possible with a plugin. Shame though as I would have liked to be able to package this up so that other people could use it too! Oh well.

I just don’t think that a plugin will allow me to do what I need as they are pretty much a one off runtime thing and what I need to do needs to query the database every time that you tab out of the field so I don’t think this will work.

Oh well ho hum it’s all a learning experience I suppose wink

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65013 Total Logged-in Users: 61
Total Topics: 82080 Total Anonymous Users: 32
Total Replies: 441126 Total Guests: 303
Total Posts: 523206    
Members ( View Memberlist )