Tuesday, March 28, 2017

Re: Django Captcha Ajax call not working

Hi Melvyin still not working



        $(".captcha_form").submit(function(event){
            event.preventDefault();
            var form = $(this)
            alert (form.serialize())
            $.ajax({
                type: "POST", 
                url: "./captcha",
                contentType: "application/json",
                data: form.serialize(),
                dataType: "json",
                success: function(data) {
                    alert(data.status);
                  },
                error: function(data) {
                    alert("NOT_OK");
                  }         
                });
        });
    });
    </script>

<form id ="captcha_form" class="captcha_form" action="./captcha" method="post">{%csrf_token%}
    {{form.as_p}}
<input type="submit" id="button" class="button" value="Invio"/>
</form>



If i make the call using form post method it validates, if use ajax post method with form.serialize() it not validates? The problem for sure ios with ajax call!

Please help out!

rgds valerio



On Monday, March 27, 2017 at 5:44:34 PM UTC+2, valerio orfano wrote:
Hi Melvyn 

thanx a lot . I will try tomorrow early morning and will let u know. Thanx. valerio

On Monday, March 27, 2017 at 3:31:38 PM UTC+2, Melvyn Sopacua wrote:

Hi,

 

{% if field.name = 'captcha' %}

 

assigns 'captcha' to field.name and returns if that succeeded. So it's always true. You probably mean:

{% if field.name == 'captcha' %}

 

From what you describe, testfield shows up and your template code says it shouldn't show up.

 

However, when debugging a problem, always reduce to the simplest case, so try with this template code:

 

<form id ="captcha_form" class="captcha_form" action="" method="post">{%csrf_token%}

{{ form }}

<input type="submit" id="button" class="button" onclick="captcha()" value="Invio"/>

</form>

 

On Monday 27 March 2017 05:43:53 valerio orfano wrote:

> testfield is where i type my captcha, sorry

>

> On Monday, March 27, 2017 at 2:38:15 PM UTC+2, valerio orfano wrote:

> > Hi Melvyn thanx for ur reply,

> >

> > this is my form.

> >

> > class AjaxForm(forms.ModelForm):

> > captcha = CaptchaField()

> >

> > class Meta:

> > model = ajaxModel

> > exclude = []

> >

> > class ajaxModel(models.Model):

> > testfield = models.TextField(null=True, blank=True)

> >

> > If i don't use a ajaxmodel a get an error, so testfield is just a

> > dummy field, just to avoid error.

> >

> > valerio

> >

> > On Monday, March 27, 2017 at 2:22:44 PM UTC+2, Melvyn Sopacua wrote:

> >> On Monday 27 March 2017 04:46:06 valerio orfano wrote:

> >> > {% if field.name = 'captcha' %}

> >>

> >> It may not make a difference if you only have one visible field,

> >> but this is not a comparison.

> >>

> >>

> >> Melvyn Sopacua

 

--

Melvyn Sopacua

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/10f4a9e3-4297-44c2-9840-2b09773cfbee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment