Re: Why does my django form with recaptcha send data even empty the recaptcha?

2021-03-13 Thread Sergei Sokov
html


{% csrf_token %}
{{form.choice_services}}
{{form.name}}
{{form.telephone_number}}
{{form.email}}
{{form.message}}
{{form.contact_text}}
{{ form.captcha }}





https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key";>

window.onload = function() {
var $recaptcha = document.querySelector('#g-recaptcha-response');

if($recaptcha) {
$recaptcha.setAttribute("required", "required");
}
  const $form = document.querySelector('form');
  $form.addEventListener('submit', (event) => {
event.preventDefault();
console.log('prevented submit by code for demo');
  });
};


css

#g-recaptcha-response {
display: block !important;
position: absolute;
margin: -78px 0 0 0 !important;
width: 302px !important;
height: 76px !important;
z-index: -99;
opacity: 0;
}

пятница, 12 марта 2021 г. в 21:06:56 UTC+1, RyuCoder: 

> Remove below line and try again
>
> self.fields['captcha'].widget.attrs['required'] = 'True'
>
>
> If the problem persists, try some js or jquery validation in frontend
>
>
>
>
>
> On Thu, Mar 11, 2021, 9:19 PM Gabriel Araya Garcia  
> wrote:
>
>> Camarada Sokov:
>> Your code is very difficult to understand at first sight. I did not know 
>> about ReCaptchaField().
>> But, is interesting to learn something new.
>>
>> Recards,
>>
>> Gabriel Araya Garcia
>> GMI - Desarrollo de Sistemas Informáticos
>> from Santiago de Chile
>>
>>
>>
>> El jue, 11 mar 2021 a las 12:40, Sergei Sokov () 
>> escribió:
>>
>>> I put the google recaptcha V2 to my django project form. It looks like 
>>> working, but if I leave empty the recaptcha checkbox my form is sent still.
>>>
>>> forms.py
>>> from django import
>>> forms from captcha.fields
>>> import ReCaptchaField
>>> from django.forms import Textarea
>>> from .models import *
>>> class CustomerForm(forms.ModelForm):
>>> captcha = ReCaptchaField( public_key='key', private_key='key', )
>>> class Meta:
>>> model = Customer fields = '__all__'
>>> def __init__(self, *args, **kwargs):
>>> # get 'user' param from kwargs
>>> user = kwargs.pop('user', None)
>>> super().__init__(*args, **kwargs)
>>> self.fields['message'].widget = Textarea(attrs={'rows': 4})
>>> self.fields['i_have_read_rules'].widget.attrs['required'] = 
>>> 'True'
>>> self.fields['i_agree'].widget.attrs['required'] = 'True'
>>> self.fields['captcha'].widget.attrs['required'] = 'True'
>>> for field in self.fields:
>>> self.fields[field].widget.attrs['class'] = 'form-control'
>>> self.fields['i_have_read_rules'].widget.attrs['class'] = 
>>> 'form-check'
>>> self.fields['i_agree'].widget.attrs['class'] = 'form-check'
>>>
>>> html
>>> 
>>> {% csrf_token %}
>>> Выберите услугу
>>> >> class="form-group">{{form.choice_services}}
>>> {{form.name}}
>>> >> class="form-group">{{form.telephone_number}}
>>> {{form.email}}
>>> {{form.message}}
>>> {{form.contact_text}}
>>>  {{ 
>>> form.captcha }}
>>> 
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/e18dcba2-07e2-44d9-ace6-744a2bb69234n%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAKVvSDD_HZmL%2BUVgsFVZgQCuyuhCs3Ofe2DkOtne-ydp%2B3joyw%40mail.gmail.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f3ec25b0-c6b2-4559-9402-566e11

Re: Why does my django form with recaptcha send data even empty the recaptcha?

2021-03-12 Thread Chetan Ganji
Remove below line and try again

self.fields['captcha'].widget.attrs['required'] = 'True'


If the problem persists, try some js or jquery validation in frontend





On Thu, Mar 11, 2021, 9:19 PM Gabriel Araya Garcia <
gabrielaraya2...@gmail.com> wrote:

> Camarada Sokov:
> Your code is very difficult to understand at first sight. I did not know
> about ReCaptchaField().
> But, is interesting to learn something new.
>
> Recards,
>
> Gabriel Araya Garcia
> GMI - Desarrollo de Sistemas Informáticos
> from Santiago de Chile
>
>
>
> El jue, 11 mar 2021 a las 12:40, Sergei Sokov ()
> escribió:
>
>> I put the google recaptcha V2 to my django project form. It looks like
>> working, but if I leave empty the recaptcha checkbox my form is sent still.
>>
>> forms.py
>> from django import
>> forms from captcha.fields
>> import ReCaptchaField
>> from django.forms import Textarea
>> from .models import *
>> class CustomerForm(forms.ModelForm):
>> captcha = ReCaptchaField( public_key='key', private_key='key', )
>> class Meta:
>> model = Customer fields = '__all__'
>> def __init__(self, *args, **kwargs):
>> # get 'user' param from kwargs
>> user = kwargs.pop('user', None)
>> super().__init__(*args, **kwargs)
>> self.fields['message'].widget = Textarea(attrs={'rows': 4})
>> self.fields['i_have_read_rules'].widget.attrs['required'] = 'True'
>> self.fields['i_agree'].widget.attrs['required'] = 'True'
>> self.fields['captcha'].widget.attrs['required'] = 'True'
>> for field in self.fields:
>> self.fields[field].widget.attrs['class'] = 'form-control'
>> self.fields['i_have_read_rules'].widget.attrs['class'] =
>> 'form-check'
>> self.fields['i_agree'].widget.attrs['class'] = 'form-check'
>>
>> html
>> 
>> {% csrf_token %}
>> Выберите услугу
>> {{form.choice_services}}
>> {{form.name}}
>> > class="form-group">{{form.telephone_number}}
>> {{form.email}}
>> {{form.message}}
>> {{form.contact_text}}
>>  {{
>> form.captcha }}
>> 
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/e18dcba2-07e2-44d9-ace6-744a2bb69234n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAKVvSDD_HZmL%2BUVgsFVZgQCuyuhCs3Ofe2DkOtne-ydp%2B3joyw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMKMUjuA8GZ6XTq8FvBJh0HEfvzezrtJnvXj%3DH1k2vBDkoZLUg%40mail.gmail.com.


Re: Why does my django form with recaptcha send data even empty the recaptcha?

2021-03-11 Thread Gabriel Araya Garcia
Camarada Sokov:
Your code is very difficult to understand at first sight. I did not know
about ReCaptchaField().
But, is interesting to learn something new.

Recards,

Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos
from Santiago de Chile



El jue, 11 mar 2021 a las 12:40, Sergei Sokov ()
escribió:

> I put the google recaptcha V2 to my django project form. It looks like
> working, but if I leave empty the recaptcha checkbox my form is sent still.
>
> forms.py
> from django import
> forms from captcha.fields
> import ReCaptchaField
> from django.forms import Textarea
> from .models import *
> class CustomerForm(forms.ModelForm):
> captcha = ReCaptchaField( public_key='key', private_key='key', )
> class Meta:
> model = Customer fields = '__all__'
> def __init__(self, *args, **kwargs):
> # get 'user' param from kwargs
> user = kwargs.pop('user', None)
> super().__init__(*args, **kwargs)
> self.fields['message'].widget = Textarea(attrs={'rows': 4})
> self.fields['i_have_read_rules'].widget.attrs['required'] = 'True'
> self.fields['i_agree'].widget.attrs['required'] = 'True'
> self.fields['captcha'].widget.attrs['required'] = 'True'
> for field in self.fields:
> self.fields[field].widget.attrs['class'] = 'form-control'
> self.fields['i_have_read_rules'].widget.attrs['class'] =
> 'form-check'
> self.fields['i_agree'].widget.attrs['class'] = 'form-check'
>
> html
> 
> {% csrf_token %}
> Выберите услугу
> {{form.choice_services}}
> {{form.name}}
> {{form.telephone_number}}
> {{form.email}}
> {{form.message}}
> {{form.contact_text}}
>  {{
> form.captcha }}
> 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e18dcba2-07e2-44d9-ace6-744a2bb69234n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKVvSDD_HZmL%2BUVgsFVZgQCuyuhCs3Ofe2DkOtne-ydp%2B3joyw%40mail.gmail.com.


Why does my django form with recaptcha send data even empty the recaptcha?

2021-03-11 Thread Sergei Sokov
I put the google recaptcha V2 to my django project form. It looks like 
working, but if I leave empty the recaptcha checkbox my form is sent still.

forms.py
from django import
forms from captcha.fields
import ReCaptchaField
from django.forms import Textarea
from .models import *
class CustomerForm(forms.ModelForm):
captcha = ReCaptchaField( public_key='key', private_key='key', )
class Meta:
model = Customer fields = '__all__'
def __init__(self, *args, **kwargs):
# get 'user' param from kwargs
user = kwargs.pop('user', None)
super().__init__(*args, **kwargs)
self.fields['message'].widget = Textarea(attrs={'rows': 4})
self.fields['i_have_read_rules'].widget.attrs['required'] = 'True'
self.fields['i_agree'].widget.attrs['required'] = 'True'
self.fields['captcha'].widget.attrs['required'] = 'True'
for field in self.fields:
self.fields[field].widget.attrs['class'] = 'form-control'
self.fields['i_have_read_rules'].widget.attrs['class'] = 
'form-check'
self.fields['i_agree'].widget.attrs['class'] = 'form-check'

html

{% csrf_token %}
Выберите услугу
{{form.choice_services}}
{{form.name}}
{{form.telephone_number}}
{{form.email}}
{{form.message}}
{{form.contact_text}}
 {{ 
form.captcha }}


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e18dcba2-07e2-44d9-ace6-744a2bb69234n%40googlegroups.com.