inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 26, 2012 11:56:57 GMT -8
How would I create a function that runs on the click of the submission button on the post page?
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Nov 26, 2012 12:35:19 GMT -8
It depends on what you are doing.
Do you need to update a key? Or just something else?
If you are just doing something else non key related, bind a "validated" event to the form.
If you need an example, let me know.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 26, 2012 13:18:29 GMT -8
I have built a system where users must read and accept rules before posting. This part of the code is going to check for a cookie whenever the submit or reply buttons are pushed. An example would be nice...
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Nov 26, 2012 13:36:46 GMT -8
Right, first thing I suggest is to read up about the EU Cookie Law just so you understand when an opt-in from the user is required. In your case, since it's storing a preference, you should be fine, but please read up on it anyway.
Here is some code from my Monetary System plugin. This will show you how I bind the event (this is older code and will be using event hooks in next update), and how to carry on with the submit.
The reason for the "validated" event, is because a regular "submit" event handler will fire off while the form may not be ready for posting (i.e forgot subject).
var what = this; var the_form;
if(yootil.location.check.posting()){ the_form = yootil.form.post_form(); } else if(yootil.location.check.thread()){ the_form = yootil.form.post_quick_reply_form(); }
if(the_form.length){ the_form.bind("validated", function(event){ if(!what.processed){ if(what.is_new_thread || what.is_editing){ var poll_input = $(this).find("input[name=has_poll]"); what.is_poll = (poll_input && poll_input.val() == 1)? true : false; } yootil.ajax.bind("complete", this, function(){ this.submit(); }, "/plugin/key/set/", this); what.apply_posting_money(); return; } this.submit(); }); }
Another....
the_form.bind("validated", function(event){ if(not_agree){ alert("Something here"); return; } this.submit(); } Obviously "the_form" should be a reference to the post form.
Hope that helps.
|
|
#e61919
1
0
1
Sept 28, 2023 13:31:20 GMT -8
VS Admin
20,147
January 2000
admin
|
Post by VS Admin on Nov 26, 2012 13:37:44 GMT -8
I strongly recommend using a plugin key instead of a cookie.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 26, 2012 14:16:49 GMT -8
Peter - The only thing the cookie will do is set it's value to "accepted". Then whenever you submit a post the forum will check to make sure that the cookie is there before allowing you to post...that should be fine right? As to your coding info. First off in your second code tag are you missing a ) in there? I see a ( at the beginning right before Validated, but don't see it closed. Would it go at the end like so? the_form.bind("validated", function(event){ if(not_agree){ alert("Something here"); return; } this.submit(); )}; VS Admin - I will look into using keys. I do think I should do it both ways though. Maybe build two versions. The thing is don't you have a limited number of keys? So maybe people wouldn't want to waist one of their keys for this code...i dunno just a thought
|
|
#e61919
1
0
1
Sept 28, 2023 13:31:20 GMT -8
VS Admin
20,147
January 2000
admin
|
Post by VS Admin on Nov 26, 2012 14:18:35 GMT -8
Peter - The only thing the cookie will do is set it's value to "accepted". Then whenever you submit a post the forum will check to make sure that the cookie is there before allowing you to post...that should be fine right? As to your coding info. First off in your second code tag are you missing a ) in there? I see a ( at the beginning right before Validated, but don't see it closed. Would it go at the end like so? the_form.bind("validated", function(event){ if(not_agree){ alert("Something here"); return; } this.submit(); )}; VS Admin - I will look into using keys. I do think I should do it both ways though. Maybe build two versions. The thing is don't you have a limited number of keys? So maybe people wouldn't want to waist one of their keys for this code...i dunno just a thought Cookies slow down users browsers. If you set a cookie, that cookie is then sent to the ProBoards server on every single pageview. The more cookies there are, the slowest the response time for the end user when loading a page. Yes, plugin keys are limited, but we are providing a way for you to increase the number of plugin keys a forum gets. Most forums will never get near their plugin key limits, and those that do can upgrade for a small fee.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 26, 2012 14:23:01 GMT -8
Ok, I basically have the cookie one finished...so I am gonna finish it, but the next version I will spend the time and figure out how the keys work
|
|
#e61919
1
0
1
Sept 28, 2023 13:31:20 GMT -8
VS Admin
20,147
January 2000
admin
|
Post by VS Admin on Nov 26, 2012 14:23:43 GMT -8
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Nov 26, 2012 14:38:11 GMT -8
Peter - The only thing the cookie will do is set it's value to "accepted". Then whenever you submit a post the forum will check to make sure that the cookie is there before allowing you to post...that should be fine right? As to your coding info. First off in your second code tag are you missing a ) in there? I see a ( at the beginning right before Validated, but don't see it closed. Would it go at the end like so? the_form.bind("validated", function(event){ if(not_agree){ alert("Something here"); return; } this.submit(); )}; VS Admin - I will look into using keys. I do think I should do it both ways though. Maybe build two versions. The thing is don't you have a limited number of keys? So maybe people wouldn't want to waist one of their keys for this code...i dunno just a thought I wrote that on the fly as a guide, but yes, it was missing the closing parentheses. Just use a key, which is much much easier in the long run, or if you really don't want too, then go down the HTML 5 route for now.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 26, 2012 14:55:42 GMT -8
I like literally have everything written...i just needed this function. I will go back and write it with a key after I finish this, but I'd like to get this done first before i totally take a different rout Ok so here is what I have for this part right now (It's really similar to what you have) but it doesn't want to work I have an alert in there to make sure it's getting to that part of the code. The alert goes off, but the checkRulesCookie function never runs... var the_form; if(yootil.location.check.posting()){ the_form = yootil.form.post_form(); } else if(yootil.location.check.thread()){ the_form = yootil.form.post_quick_reply_form(); } if(the_form.length){ the_form.bind("validated", function(event){ alert("this works"); checkRulesCookie(); }); }
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Nov 26, 2012 15:00:16 GMT -8
Do you have the Yootil Library imported and enabled?
Did you check errors?
Post you "checkRulesCookie" function.
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 26, 2012 15:07:04 GMT -8
Yes, I have checked errors with firebug and nothing is popping up function checkRulesCookie() { var rules=getCookie("hello"); if (rules != accepted) { var d=confirm("Before browsing the site you must agree to rules."); if(d==true) { window.location = "/page/rule" } else { window.location = "/logout" alert("You have been logged out.") } } }
|
|
inherit
2671
0
May 14, 2013 14:40:03 GMT -8
Peter
🐺
10,615
February 2002
peter3
|
Post by Peter on Nov 26, 2012 15:45:03 GMT -8
Post the plugin if you can, be easier for us to go over that instead.
Anyway, one mistake I see is this...
if (rules != accepted) {
The value from "getCookie" is most likely a String right?
if (rules != "accepted") {
|
|
inherit
153968
0
Nov 19, 2012 15:03:05 GMT -8
Thesealion
New Phone Who Dis?
4,124
April 2010
joemaggio
|
Post by Thesealion on Nov 26, 2012 16:15:07 GMT -8
Ok...it's rather complex right now so bare with me Here is the plugin: Rules.pbp (881 B) This plugin redirects to a custom page with this code on it. Blablablablablablabla
<script> function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } }
function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function acceptRules() { setCookie('rules','accepted',365); window.location = "/page/test" } </script>
<button id="accept_rules" onclick="acceptRules();" type="button">Accept Rules!</button> Here's how it works, or is supposed to work. Whenever you click the submit button on the posting page the plugin checks to see if you have the cookie "rules" set as "accepted." If "rules" is set as "accepted" then it should just let you post. If not, it should redirect you to the custom page where the rules were. On that page there is a button (the one in the code above) that creates the cookie "rules" and sets it as "accepted." Edit: In the plugin i have set the cookie it's checking as "hello" instead of "rules" this was just for a test. I forgot to change it back when i was done...
|
|