Guys I would like to add a few extra fields to new thread without Xthreads?
Please share your tips and codes?
I know I would need to create a table to store data but I am not sure how to then assign that data to its thread and how to securely insert it into the DB.
I've added a few custom fields to my threads table, so these are the steps that I used along with some sample code.
- Add new table fields to the mybb_threads table. It depends on what you're doing, but that takes care of needing to link up the thread/extra field.
$db->add_column("threads", "your field name", "type of field you want to enter");
- You'd have to hook it into the showthread template to display the contents of the field.
- To actually insert the field into the database on a new thread, you'd hook into newthread_do_newthread_end. Your function would look something like this:
function test_do_newthread()
{
global $db, $mybb, $tid;
$foo = array(
"test" => $db->escape_string($mybb->input['test'])
);
$db->update_query("threads", $foo, "tid='{$tid}'");
}
That has worked well enough for me. myBB usually just uses the escape_string function, so as long as you have that as a minimum, you should be fine with security.
If the value is something a user is inputting htmlspecialchars_uni should also be used on the input.
That is so cool only one thing how to incorporate: "htmlspecialchars_uni"
function test_do_newthread()
{
global $db, $mybb, $tid;
$foo = array(
"test" => $db->escape_string($mybb->input['test'])
);
$something = htmlspecialchars_uni($foo);
$db->update_query("threads", $foo, "tid='{$tid}'");
}
What link should look like for this: "$mybb->input['test']"
htmlspecialchars_uni only accepts a string as far as I remember; it doesn't accept an array. You can do this though
$foo = array (
"test" => $db->escape_string(htmlspecialchars_uni($mybb->input['test']))
);
+1 @dragonexpert could you please help me with creating input field to work with this code?