You need to see this

Handle problems or report system bug
Hariph
Posts: 45
Joined: Tue May 23, 2023 9:33 pm

You need to see this

Post by Hariph »

I have a code that enables user to write thier own forum post with title and content, so I modified the code for user to be able to upload thumbnails as well but it's not working, can anyone help with this
samuel_anttunes
Posts: 29
Joined: Thu Mar 09, 2023 12:25 pm

Re: You need to see this

Post by samuel_anttunes »

Show me the codes you're using.
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: You need to see this

Post by francisco »

Hi, here's a Lua script to upload the thumbnail and generate the post in a single form!
Be sure to set the Script as visible only to "Admin & user".

The script first uploads the thumbnail and if the upload is successful the post is created with the thumbnail link added.

Code: Select all

html_form = [=[
<form method="post" enctype="multipart/form-data">
%s <!-- Error message goes here -->
Title:<br>
<input type="text" name="post_title" value="%s" required><br>
Content:<br>
<textarea name="post_content" required>%s</textarea><br>
Thumbnail:<br>
<input type="file" name="post_thumbnail" required><br>
<input type="submit" value="Create post">
</form>
]=]

if (req.method == "POST") then
    error_message = nil

    local upload_param = {
        folderid = 71055, --> Change to the thumbnails folder
        file = req.files.post_thumbnail.full_path
    }
    local upload_ok, upload, info, upload_error = api.file_create(upload_param)
    if (upload_ok) then
        local post_param = {
            forumid = 24031, --> Change to the posts forum
            title = req.post.post_title,
            content = req.post.post_content,
            thumb = upload[0].cdn_link
        }
        local post_ok, post, info, post_error = api.post_create(post_param)
        if (post_ok) then
            url.redirect("/post?id=" .. post[0].id) --> Modify to where you would like to take the user after they generate the post
        else
            error_message = string.format("Post creation error: %s - %s: %s", post, info, post_error)
        end

    else
        error_message = string.format("Thumbnail upload error: %s - %s: %s", upload, info, upload_error)
    end

    if (error_message) then
        html_error = [=[<div class="error-message">%s</div>]=]
        error_message = string.format(html_error, error_message)
    end
end

print(string.format(html_form, error_message or "", req.post.post_title or "", req.post.post_content or ""))
Last edited by francisco on Fri Feb 16, 2024 4:04 pm, edited 1 time in total.
😴
vikkas
Posts: 84
Joined: Sun May 07, 2023 9:28 am

Re: You need to see this

Post by vikkas »

Super, thank you
vikkas
Posts: 84
Joined: Sun May 07, 2023 9:28 am

Re: You need to see this

Post by vikkas »

Image
Hariph
Posts: 45
Joined: Tue May 23, 2023 9:33 pm

Re: You need to see this

Post by Hariph »

Thank you so much in adavnce I would try all of these,
But for those that asked this is the line of code I used to update the thumbnail, please correct me if I am wrong. What could be wrong

Code: Select all

<div class="menu"><b>Book cover:</b><br/><input type="file" name="thumb" id="thumb"></div>
Then I used %thumbnail% or %thumb% tag to call out the thumbnail at the page where I am displaying the forum list posts
Last edited by Hariph on Fri Feb 16, 2024 11:59 am, edited 3 times in total.
Hariph
Posts: 45
Joined: Tue May 23, 2023 9:33 pm

Re: You need to see this

Post by Hariph »

This is the full code here

Code: Select all

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<form id="form" method="post">
{{IFSET(%notify%)@THEN(<div class="rmenu">)}}
{{VALUE(%notify%)@IFEQ(Success)@THEN(%notify%<script>window.location.href='/'</script>)@ELSE(%notify%)}}
{{IFSET(%notify%)@THEN(</div>)}}

<input type="hidden" value="{{GET(forum)}}" name="forum">
<div class="menu">All inputs marked with (*) are important <br/><b>*Book title:</b><br/><input type="text" name="title" id="title"></div>
<input type="hidden" value="{{GET(forum)}}" name="forum">
<div class="menu"><b>Book cover:</b><br/><input type="file" name="thumb" id="thumb"></div>
<div class="menu">
<b>*Content body:</b> <a id="upload">[ <i class="fa fa-upload" aria-hidden="true"></i> Insert image ]</a><br/><i style="color:gray">If you want a newline in your text, please use two spaces or use BBCODE such as <b>[br]</b>, for more info please refer back to ra-academy, <br/><font color="red"><b>NOTE:</b></font> that your content has to be reviewed by the admin before being published but if it does reach our standard for writing then shall it remain pending/deleted </i><br/>
<div class="redactor_box" style="border-bottom: 1px solid #D7EDFC;margin-bottom:2px;"><style>.color a {float:left; display: block; width: 10px; height: 10px; margin: 1px; border: 1px solid black;}</style>
<script language="JavaScript" type="text/javascript">function tag(e,t){if(document.selection)document.form.msg.focus(),document.form.document.selection.createRange().text=e+document.form.document.selection.createRange().text+t;else if(null!=document.forms.form.elements.msg.selectionStart){var n=document.forms.form.elements.msg,o=n.value,s=n.selectionStart,l=n.selectionEnd-n.selectionStart;n.value=o.substr(0,s)+e+o.substr(s,l)+t+o.substr(s+l)}else document.form.msg.value+=e+t}function show_hide(e){obj=document.getElementById(e),"none"==obj.style.display?obj.style.display="block":obj.style.display="none"}</script>
<ul class="redactor_toolbar">
<li class="redactor_btn_group"><a href="javascript:tag('[b]', '[/b]')"><i class="fa fa-bold" aria-hidden="true"></i></a><a href="javascript:tag('[i]', '[/i]')"><i class="fa fa-italic" aria-hidden="true"></i></a><a href="javascript:tag('[u]', '[/u]')"><i class="fa fa-underline" aria-hidden="true"></i></a><a href="javascript:tag('[s]', '[/s]')"><i class="fa fa-strikethrough" aria-hidden="true"></i></a></li>
<li class="redactor_btn_group"><a href="javascript:tag('[center]', '[/center]')"><i class="fa fa-align-center" aria-hidden="true"></i></a><a href="javascript:tag('[right]', '[/right]')"><i class="fa fa-align-right" aria-hidden="true"></i></a><a href="javascript:tag('[code]', '
')"><i class="fa fa-code" aria-hidden="true"></i></a><a href="javascript:tag('', '')"><i class="fa fa-link" aria-hidden="true"></i></a></li>
<li class="redactor_btn_group"><a href="javascript:tag('Image', '')"><i class="fa fa-picture-o" aria-hidden="true"></i></a><li>
</ul>
<textarea name="msg" rows="8" id="comment-comment"></textarea></div></div>
<div class="menu" style="text-align:center"><button type="submit" style="padding:15px;font-size:16px" id="submit">Publish</button></div>[/code]

<br/><br/>

Config

Code: Select all

<forumid>{{POST(forum)}}</forumid><title>{{POST(title)}}</title>
<content>{{POST(msg)@REPLACE(["  ","[br]"])}}</content>
<status>pending</status>
<thumb>{{POST(thumb)}}</thumb>

But the thumbnail isn't working, please who can tell what the problem might be
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: You need to see this

Post by francisco »

Hariph wrote: Fri Feb 16, 2024 11:39 am [...]
But the thumbnail isn't working, please who can tell what the problem might be
Hello! The Post Creator function expects the value of the thumb parameter to be a string, as it is not capable of uploading files.
That's why in the Lua code I provided, the thumbnail is first being uploaded using the File Uploader function and only then will the cdn_link return be used as the value for the thumb parameter of the Post Creator.
😴
Hariph
Posts: 45
Joined: Tue May 23, 2023 9:33 pm

Re: You need to see this

Post by Hariph »

Ooh that's why it wasn't working, well I tried the lua cold you provided, it actually worked but its working for only one forum category but I wanted it to work for all forum categories and not just one alone, I want the user to be able to select the category they want to post to, or better still the url can catch the category where the user is coming from and update thier post on that category
User avatar
francisco
Posts: 62
Joined: Tue Mar 07, 2023 1:48 pm
Location: Brazil
Contact:

Re: You need to see this

Post by francisco »

Hariph wrote: Mon Feb 19, 2024 10:36 am Ooh that's why it wasn't working, well I tried the lua cold you provided, it actually worked but its working for only one forum category but I wanted it to work for all forum categories and not just one alone, I want the user to be able to select the category they want to post to, or better still the url can catch the category where the user is coming from and update thier post on that category
What url structure are you using on your forum?
😴
Post Reply