Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

Adding custom fields to Posts

Aloittaja Tiago Lourenç', lokakuu 09, 2013, 11:40:51 AP

« edellinen - seuraava »

Tiago Lourenç'

Hello folks.

After spending quite a lot hours trying to understand how Posting works on SMF, I still didn't understand it, at all.

Sometime ago I successfully added custom fields to Events.

I've done my search in the following files: Post.php, Load.php, Manage-messages.php, Sub-post.php, MessageIndex.php (...).

I'm pretty sure it's on Post.php where everything happens, but I find the code a little confusing (for me...) and couldn't get it to work yet.

Note: I need some tips on how to insert and update the values of the custom fields in the database, I have the graphical part set up already.

Thank you,
Tiago Lourenço

margarett

So, you have some extra fields being displayed in Post.template.php (other than Subject/body), and you want to submit them to the database as part of the post?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Tiago Lourenç'

Lainaus käyttäjältä: margarett - lokakuu 09, 2013, 01:19:58 IP
So, you have some extra fields being displayed in Post.template.php (other than Subject/body), and you want to submit them to the database as part of the post?

Hello margarett.

That's exactly what I want.

I have been trying to make it work in Post.php but for some weird reason nothing seems to work. I'm sure it's just lack of experience since I'm new to PHP.

What I understood from the code is that the INSERTS and UPDATES are done separately for each thing such as is_sticky, is_locked, subject,  not everything once...

Thank you.  :)

margarett

That's a heck of a task you have ahead of you :P

My honest advice: take easy. If you are new to PHP and specifically to SMF's structure, you will need a LOT perseverance to accomplish that.

Now, to start: what EXACTLY you want to achieve with your special implementation? Because you might be using the wrong tool for the job.
Also, you need to understand that, if you change the default behaviour of SMF, you will break compatibility a LOT of things.
Furthermore, ALL your posts will have that new structure throughout the forum. Do you want that or maybe a specific part with a specific layout?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Tiago Lourenç'

First of all, thank you for the advice. Means a lot.

Answering your question. Basically the final result expected is something like this:



Where each image is linked to a topic. All this graphical part is done and it gets the images from the database and all. In my point of view, crappy way of doing this but... I would prefer to do such thing in another way but it wouldn't be as fast as doing it like this.

Before doing anything, I pondered making it with custom pages, but that would mean to recreate the topics system or find another way to link that to topics. Not the best thing too.

That said, the structure would be only used by Admins and would only be shown when creating/editing topics.

I'm planning to do a CMS as soon as I have the knowledge to, so this is a way of plug holes until that's done. Making a CMS from scratch would allow to build the systems thinking on situations like this one.

Thank you.

margarett

But that's a printscreen from MessageIndex, not from a Post...

So, do you wish to create a normal post BUT have a custom MessageIndex to show the list of posts in a different way (like you show)?
OR
Do you want to create and show custom posts/topics? Please note: posts CONTENT, not topics list ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Tiago Lourenç'

#6
Lainaus käyttäjältä: margarett - lokakuu 09, 2013, 02:53:10 IP
But that's a printscreen from MessageIndex, not from a Post...

So, do you wish to create a normal post BUT have a custom MessageIndex to show the list of posts in a different way (like you show)?
OR
Do you want to create and show custom posts/topics? Please note: posts CONTENT, not topics list ;)

Well... I want to show some topics in a different way. I got that working by creating some custom columns in the database @ topics and in MessageIndex made some conditional expressions. It's working like a charm.

But to do this I had to add the values such as the images link in the database manually. The only thing I can't do now is making the labels, I added in the Post.template, update the database with the information needed for the topics in MessageIndex?

Basically when an Admin creates a topic there will be a option "Race [ x ]". When loading: If the topic is a race then it will show in a way (with the link stored in the database, added along with the option I just mentioned), else it will show normally.

By looking at your signature, you're Portuguese right? We can speak in Portuguese if you want, so you'll understand better what I want.   ;)

SoLoGHoST

Lainaus käyttäjältä: Tiago Lourenç' - lokakuu 09, 2013, 02:45:03 IP
First of all, thank you for the advice. Means a lot.

Answering your question. Basically the final result expected is something like this:



Where each image is linked to a topic. All this graphical part is done and it gets the images from the database and all. In my point of view, crappy way of doing this but... I would prefer to do such thing in another way but it wouldn't be as fast as doing it like this.

Before doing anything, I pondered making it with custom pages, but that would mean to recreate the topics system or find another way to link that to topics. Not the best thing too.

That said, the structure would be only used by Admins and would only be shown when creating/editing topics.

I'm planning to do a CMS as soon as I have the knowledge to, so this is a way of plug holes until that's done. Making a CMS from scratch would allow to build the systems thinking on situations like this one.

Thank you.

How do you want it to link to topics? Through an attachment?  IMHO, you can do this simply with a Portal system and some code in a Custom PHP Module/Block.  For example, you could link to topic attachments with a specific prefix and/or suffix name attached to them, and only allow specific Membergroups to post attachments for that board.  Than use a custom module/block to grab attachments with that prefix/suffix on them.

But if you are persistent on doing this within SMF yourself, than you'll also need to edit "MessageIndex.php" and "MessageIndex.template.php".

For Creating and/or Modifying Posts (Inserting into the database), this is done in "Post.php" (Source code that handles the $_POST[] variables in "Post2()" function) as well as "Subs-Post.php" and "Post.template.php" (where the $_POST variables get defined within the form element as <input>, <textarea> tags).

For displaying the results from the database above topic listings, "MessageIndex.php" will need edits to grab the values from the database, and than MessageIndex.template.php is used to actually display the results from the $context[] array/key variable that you define in MessageIndex.php to hold the results of the database values.

No edits needed to these files:  Load.php, Manage-messages.php

Tiago Lourenç'

Got it guys! Thank you for your help.

I can't tell right now exactly how I did it, but it was nothing more than looking through the files and put some time on it.

For those who might want to see the final result:

hxxp:xtremerpm.org/index.php?board=297.0 [nonactive]

(Are links allowed?)

See ya around. Thank you.  :)

Advertisement: