PDA

View Full Version : How can I insert new fields within an existing admin form via plugin/hooks?


SToP_GAP
09-20-2012, 06:13 PM
Hi, I hope someone can help...

I'm trying to extend the forum.php admin form by adding a few custom fields in there. I won't get into what those will be and explaining all that... basically if someone could show me how to add a direct copy of the "Title" field directly after that in the forum this would be most helpful.

Line 140 of forum.php is:

print_input_row($vbphrase['title'], 'forum[title]', $forum['title']);

I have a product & plugin defined and using the "forumadmin_edit_form" hook I can execute code just fine. What I can't work out is how to "inject" at a certain point in the output.

Essentially if I were hard editing the forum.php file, then I would copy line 140 and paste it again as line 141. How do I achieve the same from a plugin?

Many thanks :)

kh99
09-20-2012, 08:38 PM
Unfortunately, you can't. The adminCP works differently than the forum in that it doesn't use templates and just outputs html as it goes along instead of once at the end, so there's no chance to change it via str_replace() or anything like that. The best you can do (without editing the file) is to use hook forumadmin_edit_form and add it at the end. (It's fortunate that forum.php has hooks at all, a lot of the adminCP doesn't).

SToP_GAP
09-21-2012, 02:52 PM
OK, thanks for that, you saved me a lot of time wrestling with it trying to work out why it wasn't working!

For anyone else having the same issue, I found a slightly bodgy but nonetheless useful way to get this functionality (on this particular page at least). Using the earlier hook "forumadmin_start" I set the output buffering of PHP on (using ob_start() )

Then in the section where I needed to make a change, I accessed the contect of the buffer using $stringvar = ob_ get_ clean(). With a combination of this and nested output buffers I was able to do exactly what I needed.

This required a plugin for both the "forumadmin_start" hook (which turns on the buffer) and then a separate plugin at the hook point where I'm dealing with the buffered output, in this case "forumadmin_edit_form".

This is not perhaps advisable for mainstream pages as it'll introduce additional overheads on a system, but for backend pages it shouldn't cause any issues. There is potential to clash with other plugins which manipulate the page at the same time as this, especially if they do anything with the buffer so tread carefully.

kh99
09-21-2012, 04:43 PM
Nice - wish I'd thought of that. :)