PDA

View Full Version : How do I update a custom thread field on editpost?


AreaZeroOne
10-05-2007, 09:19 PM
Hi.

I created a custom field, i'll call it, Field1, that a user fills out when creating a new thread. Now i've written some plugin code so that when the new thread is created, the field1 options (option1,2,3,etc;) are sucessfully posted to the db (along with everything else).

However, i'm having trouble understanding the rest. On editpost, I can populate the field with the current selection, but I cannot update the field (one because there's nothing handling it). I'm pretty much stuck here!

So to avoid further insanity, how would I go about finishing this up?

Thanks for any help.

:edit: The fields have nothing to do with the fields one can create via the AdminCP.

Jelmertjee
11-23-2007, 09:10 AM
I know you posted this a while ago, but did you find a solution after all? I'm trying to figure this out as well... I have custom fields when creating threads, but what's the use when you can't edit them right?

I didn't get as far as you did though, could you explain (or post the code) you used to populate the fields again when editing the threads?

WhaLberg
11-23-2007, 09:15 AM
Add a plugin to editpost_update_complete hook and paste these codes:


$db->query_write("UPDATE " . TABLE_PREFIX . "post SET fieldname = " . $_POST['fieldname'] . " WHERE postid = " . $postinfo['postid'] . "");


Let me know the result.

Jelmertjee
11-23-2007, 10:36 AM
Thanks! I've got it working right now, I needed to add some quotes around the variable but that was all.

So, now I can edit the custom post fields, but they aren't automatically filled with the 'old' content yet, which had been set when creating the thread, I know how the template part works, just need the php/mysql to do it...

WhaLberg
11-23-2007, 10:43 AM
Hmmm...

This will give you what you need. Add to editpost_start.

$getinfo = $db->query_read("SELECT fieldname FROM " . TABLE_PREFIX . "post WHERE postid = " . $postinfo['postid'] . "");
$fieldinfo = $db->fetch_array($getinfo);
$fieldname = $fieldinfo['fieldname'];


To have this working, you must set your field in your edit post template as <input type="text" value="$fieldname" name="fieldname" *>

Jelmertjee
11-23-2007, 06:54 PM
Thanks again, it works like a dream now ;), is there anything I can do for you in return??

WhaLberg
11-25-2007, 03:03 PM
Just thanking is enough. :)