vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   How To Make Attachments Required ...? (https://vborg.vbsupport.ru/showthread.php?t=316858)

fai99al99 01-23-2015 04:30 AM

How To Make Attachments Required ...?
 
Hello,

I Want To Make Attachments Required For A Certain Forum
When Someone Add A New Thread , How To Do This?

Thanks for your time,

Dave 01-23-2015 08:54 AM

Hook into newthread_post_start and then check if there are any attachments present.

nerbert 01-23-2015 09:30 AM

I think you would need an event listener attached to the form that would listen for "submit" and fire a function that would use a regex to check for an attachment on the text submitted and if not preventDefault() and throw an alert or put text in the error div. I guess you would also have to have server checking that would redirect to an error message.

I may play around with it later.

nerbert 01-23-2015 11:11 PM

1 Attachment(s)
Here we go. This adds an additional hidden input to enabled forums for server checking in case someone posts with JavaScript disabled. The server returns an error message if no attachment is uploaded.

With JavaScript enabled the page will throw an alert if no attachment is uploaded. I had hoped I could distinguish between a submission and preview but that was too complicated so the alert shows for both submit and preview.

Enable this and set forum(s) in "Message Posting Check for Attachment" in Options

Two phrases can be edited by searching phrases for "ca_"

Check it thoroughly and get back if anything goes wrong.

fai99al99 01-24-2015 04:21 AM

Thank you nerbert for your time making this , I really appreciate It.

I have tested It out ,but It seems It does not work ...
It works fine when I click the Preview button only .. but when I click the submit button it does not show any alert that there is no Attachment


I have been searching and figured a another way to do this:

hook : newpost_process

PHP Code:

if($type=='thread' AND in_array($foruminfo['forumid'], array(1,2,3,4,5)))
{

$attachs $vbulletin->db->query_read("SELECT attachmentid
FROM " 
TABLE_PREFIX "attachment 
WHERE posthash = '" 
$vbulletin->db->escape_string($post['posthash']) . "'
AND userid = " 
$vbulletin->userinfo['userid'] . "
ORDER BY attachmentid"
);
if(
$vbulletin->db->num_rows($attachs) <= 0)
$errors[] = $vbphrase['required_attachments'];



nerbert 01-24-2015 04:36 AM

I'm getting the alert for submit and preview for both sets of buttons. I don't know why an event listener wouldn't fire for that. I was wondering about how to see if an attachment exists for a thread and the only other way to do it besides the new hidden input would be a query like you did. I wanted to avoid queries if possible. Did you find the checkattachmentjavascript template? That's where my JS is.

--------------- Added [DATE]1422082661[/DATE] at [TIME]1422082661[/TIME] ---------------

I see you're using a hook in newpost instead of newthread. Is this supposed to require an attachment for each post of the thread or just for the opening post of a new thread?

fai99al99 01-24-2015 05:15 AM

I have re-install It , but still the same problem facing me.
yes, checkattachmentjavascript template Is there

nerbert 01-24-2015 06:12 AM

No matter how you detect an attachment in the server code it would be nice to have an alert before it's submitted rather than getting an error message from the server and going back.

Have you tried editing in more alerts in the JavaScript to see if it's detecting the submit event , whether the function is called and how many "li" elements are in the list? When the page loads there's only one "li" in the list. I don't know what it does, all it contains is &nbsp;. After you load an attachment it should have 2 "li"s.

Try this:
Code:

<script type="text/javascript">
function Check_For_Attachment() {
        this.form = document.forms.vbform;
        this.attachlist = fetch_object("attachlist_list2");
        this.checkInput = document.createElement("input");
                this.checkInput.setAttribute("type", "hidden");
                this.checkInput.setAttribute("name", "checkattachment");
                this.checkInput.setAttribute("value", "");
        this.form.appendChild(this.checkInput);
        this.alertText = "{vb:rawphrase ca_alert_text}";
        YAHOO.util.Event.on(this.form, "submit",  function(e){
                alert("submit detected");
                checkAttachment.checkForm(e)
        })

}

Check_For_Attachment.prototype.checkForm = function(e) {
        var items = fetch_tags(this.attachlist, "li");
        alert("list items " + items.length)
        if(items.length < 2) {
                alert(this.alertText)
                YAHOO.util.Event.stopEvent(e);
        } else {
                this.checkInput.value = "true";
        }
}

YAHOO.util.Event.onDOMReady(function(e) {
        checkAttachment = new Check_For_Attachment();
});
</script>


fai99al99 01-24-2015 07:54 AM

did not work ..
I tried to change hook location and editing the code ,but still no luck

to distinguish between a submission and preview buttons I used this:
$_REQUEST['sbutton']

nerbert 01-24-2015 08:06 AM

I used $_REQUEST['preview'] but you don't get that until after it's submitted and is read in server code. It doesn't help with the JavaScript though. Well, I don't know what the problem is but as long as you can check at the server I guess you have what you need.

Too bad it didn't work for you.


All times are GMT. The time now is 03:30 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01979 seconds
  • Memory Usage 1,745KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete