2017-09-13 2 views
0

나는 스팸을 위해 recaptcha 대신 honeypot을 사용하고 싶습니다. 나는 WordPress를 운영하고있다. 일반적으로 저는 이것을 위해 중력 양식을 사용합니다. 그러나이 사이트를 개발하지 않았고 탄소 필드를 사용하여 양식 필드를 채 웁니다.형태 : 허니팟 스팸 문제

다음 js에 조건이 필요합니다. 즉 $ robotest! = ""echo "this is spam"else submit form. 내 허니팟 폼 필드는 robotest입니다 (var $ robotest = $ this.find ([ '[name = "robotest"]']);). 여기

이 양식을 제출되는 코드의 전체 덩어리입니다 :

$('.form-suite form').on('submit', function(e) { 
 
    e.preventDefault(); 
 

 
    var is_valid = true; 
 
    var data_to_send = {}; 
 

 
    var $this = $(this); 
 

 
    console.log('FORM SUBMITTED!!!!'); 
 

 
    console.log('ap test'); 
 

 
    console.log($('#event_dates').val()); 
 

 
    console.log(grecaptcha); 
 

 

 

 
    var $team_artist_event = $this.find('[name="team-artist-event"]'); 
 
    var $booking_event = $this.find('[name="game"]'); 
 
    var $first_name = $this.find('[name="fname"]'); 
 
    var $last_name = $this.find('[name="lname"]'); 
 
    var $company = $this.find('[name="company"]'); 
 
    var $email = $this.find('[name="email"]'); 
 
    var $phone = $this.find('[name="phone"]'); 
 
    var $contact_method = $this.find('[name="contact-method"]'); 
 
    var $comments = $this.find('[name="comments"]'); 
 
    var $sell_suite = $this.find(['[name="sell_suite"]']); 
 
    var $corporate_outings = $this.find(['[name="corporate_outings"]']); 
 
    var $event_dates = $this.find(['[name="event_dates"]']); 
 
    var $how_many = $this.find(['[name="how_many"]']); 
 
    var $robotest = $this.find(['[name="robotest"]']); 
 

 
    console.log('AARON HI dates:' + $event_dates.val()); 
 

 

 
    $this.find('.required').each(function() { 
 
    $(this).attr('style', 'background-color: #ddd;'); 
 

 
    var field_value = $(this).val(); 
 
    if (field_value == '') { 
 
     $(this).attr('style', 'background-color: rgba(255, 40, 40, 0.25) !important;'); 
 
     is_valid = false; 
 
    } 
 
    }); 
 

 
    //var captcha = grecaptcha.getResponse(); 
 
    //if (captcha == '') { 
 
    //is_valid = false; 
 
    //$('.captcha').attr('style', 'background-color: rgba(255, 40, 40, 0.25) //!important;'); 
 
    //} 
 
    var email_regex = /[a-z0-9._%+-][email protected][a-z0-9.-]+\.[a-z]{2,4}$/; 
 
    if (!email_regex.test($email.val())) { 
 
    $email.attr('style', 'background-color: rgba(255, 40, 40, 0.25) !important;'); 
 
    is_valid = false; 
 
    } 
 

 
    if (is_valid) { 
 
    data_to_send.team_artist_event = $team_artist_event.val(); 
 
    data_to_send.booking_event = $booking_event.val(); 
 
    data_to_send.first_name = $first_name.val(); 
 
    data_to_send.last_name = $last_name.val(); 
 
    data_to_send.company = $company.val(); 
 
    data_to_send.email = $email.val(); 
 
    data_to_send.phone = $phone.val(); 
 
    data_to_send.contact_method = $contact_method.val(); 
 
    data_to_send.comments = $comments.val(); 
 
    data_to_send.sell_suite = $sell_suite.val(); 
 
    data_to_send.corporate_outings = $corporate_outings.val(); 
 
    data_to_send.action = 'booking_form'; 
 
    data_to_send.event_dates = $('#event_dates').val(); 
 
    data_to_send.how_many = $('#how_many').val(); 
 

 
    $.ajax({ 
 
     url: ajax_object.ajax_url, 
 
     data: data_to_send, 
 
     method: 'POST', 
 
     dataType: 'json', 
 
     success: function(data) { 
 

 

 
     if (data.status == 'OK') { 
 

 
      console.log('GA send'); 
 
      ga('send', { 
 
      'hitType': 'pageview', 
 
      'page': '/form-submit/team' // Virtual page (aka, does not actually exist) that you can now track in GA Goals as a destination page. 
 
      }); 
 

 
      ga('send', 'event', 'Forms', 'submitted', 'Team Form'); 
 

 
      window.location.href = '/thank-you.php'; 
 

 
      //$('.personal-info, .event-info').hide(); 
 
      //$(' .event-info').before('<h2 class="form-success-msg">' + data.message + '</h2>'); 
 
     } 
 

 

 

 

 
     }, 
 
    }); 
 
    } 
 

 
});

+0

'email_regex '는 너무 엄격해서'.museum'과 같은 최신 (더 긴) TLD와 그 밖의 많은 법적 문자를 포함하여 많은 유효한 전자 메일 주소를 제외시킵니다. ** [**]의 왼쪽에있는 [[a-z0-9 ._ % + -] +'- [이메일 주소를 찾는 방법 또는 검증 방법] 참조 (http://www.regular-expressions.info /email.html) –

+0

지적 해 주셔서 고맙습니다. 허니팟 질문에 대한 아이디어가 있습니까? – phillystyle123

+0

그래서 분명히 알 수 있다면 로봇이 그것을 발견하고 채우지 않는 한'$ robotest'는 항상 비어 있어야합니다. not-empty 테스트는 is_valid가 거짓이어야 함을 의미하며, captcha 테스트가 주석 처리 된 위치에서 테스트가 수행 될 수 있습니다. if ($ robotest.val(). length> 0) {is_valid = false; } ' –

답변

0

허니팟 필드 <input name="robotest"> 인간이 양식을 작성하면 해당 필드이기 때문에 항상 비어 있어야합니다 인간에게서 숨어있다. 폼을 채우는 로봇은 맹목적으로 그 필드를 찾아서 그 안에 값을 넣을 수 있습니다. 귀하의 예는 사용자의 보안 문자 코드가 주석하고있다

...

//var captcha = grecaptcha.getResponse(); 
//if (captcha == '') { 
//is_valid = false; 

그 대신에 당신은 그냥 비어 있는지 확인하기 위해 허니팟 필드를 테스트 할 수 있습니다.

if ($robotest.val().length > 0) { 
    is_valid = false; 
} 
!is_valid 또는 그냥 즉시 반환 할 때에 가서 (조기 복귀) 시험의 나머지 부분을 건너 뛸 수 있습니다

:

if ($robotest.val().length > 0) { 
    return; 
} 

발신자는/핸들러는 그 준비로 설정된 경우, .

+0

어느 옵션도 작동하지 않습니다. 다음은 허니팟 필드 js입니다. – phillystyle123

+0

'var $ robotest = $ this.find ([ '[name = "robotest"]']); if ($ robotest.val(). 길이> 0) { \t $ robotest.attr ('style', 'background-color : rgba (255, 40, 40, 0.25)! important;'); \t is_valid = false; }' – phillystyle123

+0

functions.js가 양식을 제출 중입니다. 위의 허니팟 코드를 추가 할 때까지 완벽하게 작동합니다. 더 관련성있는 코드는 다음과 같습니다. – phillystyle123