MyBB Community Forums

Full Version: Plugin Form Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to write a plugin which adds a form to the postbit. I have looked at some examples in MyBB and they all seem to use AJAX and Javascript. I haven't used this before and only done HTML forms with PHP.

Can anyone give me some examples of doing forms in MyBB which take a couple of input text boxes, pass the values to a function and write the values to the database.

This might seem fairly trivial to you but I am struggling to get my function to get called by my form and hence add the required records to the database.
What exactly is the plugin going to do? Specifics would help a lot Smile
I have a forum which will be an event forum. I have already used XThreads to add an event date and location to each thread. I prefer this to using the calendar. What I want to add to each thread is under the first post, an attendance mod where people can specifiy if they will attend or not (with a yes, maybe, or no). They can also add a short comment.

I have already developed this mod for SMF but have since discovered MyBB and personally think it is the better forum software and am moving to it. I found writing the mod for SMF fairly easy but am finding it a little bit more of a struggle in MyBB (even though overall I think plugin development in MyBB is better structured and more easily encapsulated). This is because I don't know AJAX or Javascript in much detail yet.

I can post a screenshot of my SMF mod later.

Basically it is a list of the current votes of yes, maybe and no. Then a form below this with a listbox with yes,maybe,no in it, a comment text box and a submit button. When the member clicks on the submit button, their uid, the topic id, their status (yes,maybe,no), comment and time of submitting is written to my own table. This is the bit I cannot get to work.
I take it that you've built the form and everything? So you basically just need to know how to sue the database? try reading this page in the wiki: It details all the available database methods. I may be completely mistaken though haha
No, in my original form in SMF it just passed an action to the index.php file and passed all the parameters to it. In MyBB things seem to be done a little differently. From the examples I have looked at, the forms use an onclick handler which calls a javascript function when then makes an AJAX request to another function. This is the bit I am struggling with. For some reason my javascript function never gets called. I wondered if someone could help with this as it's my first attempt at using Javascript and AJAX. Even after trying to follow the other plugins as an example, I cannot get it to work.
The first bit I am unsure of is how I pass the values of the form to the javascript function.
My mistake. I had put an onclick handler but hasn't put a quote on the end. Now I have something like this

onclick="(javascript:myfunction('3', this)"

The '3' is the topic id and 'this' is how you pass the form as far as I can tell.

My javascript function looks like:

function myfunction(tid, f)

However, when I click the submit button, I get a page saying I do not have permission to access this page. What am I doing wrong?
I've installed firebug which is a great help. I can now see that my function is being called which is progress. The error I am getting is:

f.status is undefined
$status = f.status.value

f is the second parameter which is passed in as 'this' from the form. 'status' is the listbox. I thought I could then just get the value from the above command. (i.e. $status = f.status.value). Obviously not.

What am I doing wrong?
Never mind. I've solved the problems and am now making good progress. Thanks for help though.