HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Poor mans CAPTCHA

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#102441 (In Topic #20074)
Avatar

Honoured member

I have an idea and I'd like to run it past everyone to see if this is something that's relatively easy to do:

In one of my simple "contact us" catalogs, I've included a field that states something to the effect of, "Yes I'm a person and not a spam bot" and have included a drop down that has 2 options in the list:  Yes or No.

By default I have it set to NO, but what I would really like to do is have the Send button at the bottom of the page be inactive until that particular field is set to YES.

Like the title implies... a poor mans CAPTCHA.

Is this easy to do, or am I biting off more than I can chew?  Any and all help or assistance with this is very much appreciated.

Cheers!

Mark
Back to the top
 
Posted
Rating:
#102448
Avatar

Community saint

Any reason you don't want to use the existing CAPTCHA system?

In any case, having the send button disabled by default would be the trickiest part due to the way the forms are built.

But adding a "Yes" test after clicking the submit button should be easy enough and most of the logic can already be found in the CAPTCHA check logic in COMMENTS.tpl / COMMENTS_POSTING_FORM.tpl .

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#102485
Avatar

Honoured member

Thanks Temp, I'll give it a try.

I'm not against CAPTCHA in any way, in fact I had a posting last year to try to figure out how to add it to my "contact us" page:

http://ocportal.com/forum/topicview/misc/deploying/adding-captcha-to-a.htm?post_id=101289#post_101289

Unfortunately, I tried the code as Chris suggested but it didn't work as he suspected, so that's why I'm trying to find an alternative.

Hopefully moving the logic piece is fairly straightforward - if so I have a number of sites to update.
Back to the top
 
Posted
Rating:
#102545
Avatar

Honoured member

Temp,

I wasn't able to find the specific block of code in COMMENTS_POSTING_FORM.tpl, could you give me a little more specific information on what exactly to look for?

Also, I didn't find a COMMENTS.tpl template?  I'm using OCP ver. 8

Thank you.
Back to the top
 
Posted
Item has a rating of 5 (Liked by FletchLiked by superiorpyro)  
Rating:
#102558
Avatar

Community saint

This is the code form COMMENTS_POSTING_FORM.tpl

Code

{+START,IF_PASSED,USE_CAPTCHA}
   {+START,IF,{USE_CAPTCHA}}
      <script type="text/javascript">// <![CDATA[
         var form=document.getElementById('comments_form');
         form.old_submit=form.onsubmit;
         form.onsubmit=function()
            {
               document.getElementById('submit_button').disabled=true;
               var url='{$FIND_SCRIPT;,snippet}?snippet=captcha_wrong&name='+window.encodeURIComponent(form.elements['security_image'].value);
               if (!do_ajax_field_test(url))
               {
                  document.getElementById('captcha').src+='&'; // Force it to reload latest captcha
                  document.getElementById('submit_button').disabled=false;
                  return false;
               }
               document.getElementById('submit_button').disabled=false;
               if (typeof form.old_submit!='undefined' && form.old_submit) return form.old_submit();
               return true;
            };
         addEventListenerAbstract(window,'pageshow',function () {
            document.getElementById('captcha').src+='&'; // Force it to reload latest captcha
         } );
      //]]></script>
   {+END}
{+END}

And what you want is something like this:

Code

<script type="text/javascript">// <![CDATA[
   var form=document.getElementById('comments_form');
   form.old_submit=form.onsubmit;
   form.onsubmit=function()
      {
         document.getElementById('submit_button').disabled=true;
         if (TEST_FOR_NO_HERE)
         {
            document.getElementById('submit_button').disabled=false;
            return false;
         }
         document.getElementById('submit_button').disabled=false;
         if (typeof form.old_submit!='undefined' && form.old_submit) return form.old_submit();
         return true;
      };
   } );
//]]></script>


Last edit: by temp1024

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#102562
Avatar

Honoured member

Thanks very much, I'll give it a try today after work!:thumbs:

Update:

Well, I'm not sure if I'm missing something or not, but for whatever reason, adding both scripts to the page has no effect whatsoever?  The page renders as if there was no change at all, even after clearing caches, etc.

I did make the change to reflect the correct form name:

Code

var form=document.getElementById('hamfest_reservation_form');


Are there additional variables to set that I may have missed?

Thanks again for the expert advice :)


Last edit: by superiorpyro
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: