MyBB Community Forums

Full Version: Cannot display variable in editpost
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So i am very near completing my first plugin. I was able to successfully add a new field to the templates and handle the data(in the newthread.php) and insert it into the DB.

However when trying to edit it, although everything is in the template(editpost template) it doesn't work.

I have assigned the variable a value, but it's not displayed.

I have created a function and hooked it to editpost_end. I assigned the variable which is supposed to show it's value, but none is displayed..where am i wrong?
Wait what are you trying to edit? And what are you trying to show and where? You've assigned a value to a variable...but what variable?
I added a custom field in the newthread template. I was able to handle and insert the information in the database.

I added the same field to the editpost template, however when trying to display it's value for editing...it doesn't show up.
I wrote the function to assign the variable a value, hooked it to the correct editpost_end hook....and nothing.
Won't you want to hook it into editpost_start instead? Otherwise you're loading your function when the editpost has already loaded Wink
No, editpost_end is just before the output page function is used. Anyway, i was able to do it, by changing the variable in the template to $post['myfield'] which i then escape via my plugin

EDIT:
I apply the same function to three hooks. The function contains this:
   $myvar = $new_thread['myfield'] = $mybb->input['myfield'];
   
   $post->thread_insert_data['myfield'] = $db->escape_string($myvar);
   $post->post_insert_data['myfield'] = $db->escape_string($myvar);  

I apply it to these hooks:
$plugins->add_hook("datahandler_post_insert_thread", "myplugin_newthread");
$plugins->add_hook("newthread_do_newthread_start", "myplugin_newthread");
$plugins->add_hook("datahandler_post_insert_thread_post", "myplugin_newthread");

Is this correct? I mean, the plugin works, no errors appear and the data is insterted/updated. It doesn't work in drafts and preview tho.
I'm not even sure I read your post right as nothing's really making any sense to me atm but did you remember to globalize your custom variable?
I did try making it global, but it didn't display it still. Anyway, i solved my problem. Is the above posted code ok?