Creating a page with a fillable sheet [SOLVED]
#1
Hi everyone! First of all, sorry for my bad english, I am not a native speaker.

I've been looking at mybb and it looks like a really cool forum management system so I'll will like to create an Roleplay forum for me and my friends. The problem is that I want to develop my very on plugins for this RP Forum.

First of all, i would like to create a page (like: https://website.com/character-sheet/) with a character sheet that the users can fill with their character's information. Now, i know that i can create custom templates within my plugins but... How can i make it appear in an new page just for it?

I don't know if im explaining myself well, i hope so. By the way, if there is any tutorial (related with this topic in particular) i would love if you could give me a link to it. I've been looking around this forum and the "plugin development" guide but it there is not enough information for me to do something functional.

Thanks in advance!
Reply
#2
So you want users to be able to fill a form and save that information? And display such information where exactly? You want to show it only in that same page?

Your request seems a little complicated to me, if you are looking for something simple.
Reply
#3
(2019-01-03, 05:40 AM)Omar G. Wrote: So you want users to be able to fill a form and save that information? And display such information where exactly? You want to show it only in that same page?

Your request seems a little complicated to me, if you are looking for something simple.

Hi! I want them to:

1) Fill a form and save that information
2) Display it somewhere else (at their profile or in a new [custom] page)
Reply
#4
This one?
https://community.mybb.com/mods.php?action=view&pid=975
Reply
#5
(2019-01-03, 06:07 AM)effone Wrote: This one?
https://community.mybb.com/mods.php?action=view&pid=975

I know that there may be plugins to achieve what i want, but i don't want to implement third party plugins. I want to create my owns. As I said before, i want to know how to:

1) Create a new page with a form
2) Let my users fill that form
3) Save that information at my database
4) Display the information somewhere else (their profiles or at a new page)

Thanks for your help anyway!  Blush
Reply
#6
As I understand you will be more lucky checking what is already coded.

Feel free to check the code from my plugins, and once you find specific issues you might get better assistance.

I would start at creating the database table that meets your needs.
https://github.com/Sama34/OUGC-Announcem...s.php#L846

Ideally tables are created in _installation() and removed in _uninstallation().
Reply
#7
(2019-01-03, 08:14 AM)Omar G. Wrote: As I understand you will be more lucky checking what is already coded.

Feel free to check the code from my plugins, and once you find specific issues you might get better assistance.

I would start at creating the database table that meets your needs.
https://github.com/Sama34/OUGC-Announcem...s.php#L846

Ideally tables are created in _installation() and removed in _uninstallation().

Hello again Omar, i've managed myself to create a new page with a form (which is inside a custom template)! I did following MyBB documentation about Plugin Development and i think that i should work for me. With your link i know how to create a table and that pure gold, thanks a lot. Now, I have another problem! How can I handle forms?

This is my template:

<form action="#" method="POST">
    <input type="text" name="name" placeholder="Nombre" required>
    
    <input type="submit" value="Crear">
</form>

And this is the function that creates my character sheet page:

function character_sheet_form()
{
    global $mybb, $templates;

    if($mybb->get_input('character') == 'charactersheetform')
    {
        add_breadcrumb('Hoja de personaje', "misc.php?character=charactersheetform");

        $sheet_title = 'Hoja de personaje';
        eval('$sections = "' . $templates->get('character_sheet_template') . '";');

        eval("\$page = \"" . $templates->get("misc_help") . "\";");
        output_page($page);
    }
}

It is something really basic, I know, it is just for testing. Now, how can I handle that form? I think that creating a new function that handles the request should do the job, but I don't know how to start. Could you help me ?

Also, thanks a lot (again) for your help!
Reply
#8
I suppose the form action will redirect to the same page to execute its inputs, right? Then inside your character_sheet_form() function you should include a check for HTML method, and run your code inside such check if it is a post method (which it is as per your above code). In the following plugin I add a new page inside the moderator panel, and imply check if the HTML method is by post, then run my verification and insert code.
https://github.com/Sama34/OUGC-Avatar-Ap...l.php#L751 (new page generation)
https://github.com/Sama34/OUGC-Avatar-Ap...l.php#L779 (HTML post method check and code inside it)

I have a preference for using the same action url for both, displaying the page (not post method) and running the form post data. If you want to do it separately you can check how mybb does it itself in pretty much any page.
https://github.com/mybb/mybb/blob/featur....php#L1655 (page generation)
https://github.com/mybb/mybb/blob/featur....php#L1488 (HTML post form method code)

It seems easier to me to display in-line errors and save code the way I do it, but there is not really much difference.
Reply
#9
Remember to use the $mybb->get_input() method to get inputs (unless you need unsanitized values) and the $db->escape_string() method to escape data being inserted into your DB.
Reply
#10
(2019-01-03, 08:44 PM)Omar G. Wrote: Remember to use the $mybb->get_input() method to get inputs (unless you need unsanitized values) and the $db->escape_string() method to escape data being inserted into your DB.

It worked like a charm! Thanks a lot, for real! One last question (really, this is the last one ;__Wink how can i get the user's data? (The one that filled the form) I want to do so to check a simple thing:

- If the user already filled the form, do not display it
- If the user haven't filled the form, let him do so

If this question is solved at the docs i would be enough with a link, i will read it!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)