Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
posting an article using ajax on the frontend?
is it possible to post content like on facebook or twitter to your txp site, by creating a form on your homepage that only the admin can see? just looking through some of those yahoo tools for starters. i’m also looking at this tutorial
Last edited by mrtunes (2009-05-25 05:25:41)
Offline
Re: posting an article using ajax on the frontend?
I’ve been looking into this for a project myself. A couple of plugins that might help:
- ign_password_protect: See especially the <txp:ign_if_logged_in> tag, which lets you show a block of code only if the viewer is logged in.
- mem_form: Library to help with writing HTML forms.
jQuery is probably the way to go here, since it comes with Textpattern. You’ll do something like this in javascript:
$('.myform').submit(function() {
var data = $('.myform').serialize();
$.post(someUrl, function() {
$('#notice').html('<p>Your article has been submitted.</p>');
});
});
The problem is, I’m not sure what ‘someUrl’ should be. It’s possible you could use “textpattern/index.php”—you’ll have to set, at minimum, step="article"
and publish="publish"
somewhere in your form so Textpattern knows what to do with the data you’re sending it. It’s also possible you’ll need to write a plugin to process the form submit data—use the textpattern
callback for this:
if($pretext['req'] == '/mrtunes/article/submit') {
//process form submission.
exit("Success");
}
You may want to do this anyway—it would allow you to customize the return values sent back to your javascript. You could send custom error messages (or success messages) in a format easier to parse in Javascript than the entire Textpattern article submit page.
Offline
Re: posting an article using ajax on the frontend?
i would like to revisit this idea. i want to have an event listing system where i can post events on a column grid like this to-do list application does. has anyone tried anything like this?
i think connecting the front-end to the back-end would really help people post things faster on textpattern.
Offline
Re: posting an article using ajax on the frontend?
Don’t know if this will be useful to you (or anyone) in its present form; it’s entirely experimental and not documented or thoroughly tested:
It adds two new URIs to your site, both of which accept a POST request and return JSON (though add_comment will optionally parse and return a form):
http://www.example.com/atb_rest/comment_add; and
http://www.example.com/atb_rest/article_publish.
These names, and the responses they send, are very likely to change if I continue working on this.
Note that comment_add
does absolutely no spam-checking (the site I have this running on is behind my employer’s single sign on barrier and only accessible to my dozen-or-so co-workers), though it should be easy enough to make it hit the comment.save
callback so it will run the comment through any anti-spam plugins you’re using.
Last edited by atbradley (2010-04-15 19:12:08)
Offline