The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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, |
#2
|
|||
|
|||
Hook into newthread_post_start and then check if there are any attachments present.
|
#3
|
|||
|
|||
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. |
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
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:
|
#6
|
|||
|
|||
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? |
#7
|
|||
|
|||
I have re-install It , but still the same problem facing me.
yes, checkattachmentjavascript template Is there |
#8
|
|||
|
|||
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 . 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> |
#9
|
|||
|
|||
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'] |
#10
|
|||
|
|||
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. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|