Form not valid error

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Form not valid error

Dimple Mathew-2
I am trying to pass data from a form to view, but form is not valid.

I have 3 drop-downs on this form on clicking on submit, if any relavant data is available in the database it should be loaded on the template. Basically this form is a set of filters that load data based on selection.

views.py

def mentioe(request):
emp_dd= request.user.username
flag=0
if request.method == 'POST':
    form = Management_Collector(request.POST or None)
    if form.is_valid():
        m_s = form.cleaned_data.get('month_start')
        m_e = form.cleaned_data.get('month_end')
        y = form.cleaned_data.get('process_select')

        mentione= mrg_bpo.objects.filter(Q(emp_id=emp_dd) & Q(month=m_s))

        if not mentione:
            messages.error(request, 'Data is not available for your selection please consider re-selecting.')
        else:
            messages.success(request, 'Search Result Displayed Below')
        return render(request, 'mentione.html', {'form': form, 'mentione': mentione})
    else:
        print(form.errors)
        print('some issue')


else:
    print('i go to else')
    form = Management_Collector()
return render(request, 'mentione.html', {'form': form})

forms.py class Management_Collector(forms.ModelForm):

class Meta:
    model = mrg_bpo
    fields = ['month','year','process_select']
    labels = {
        "month": _(""),
    }
    widget = {
        'month':forms.HiddenInput(),
        'year':forms.HiddenInput(),
    }

index.html

<form action="" method="POST">

                    {%csrf_token%}
<select class="form-control" id="month_start" name="month_start">

  {% for i in form.month %}
<option>{{ i }}</option>
{% endfor %}</select>


<select class="form-control" id="month_end" name="month_end" > <option>

</option>
 {% for i in form.month %}
<option>{{ i }}</option>
        {% endfor %}
         </select>

{{form.year}}
{{form.process_select}}
 <button type="submit" class="btn btn-success" id="btn">Submit</button>
</form>

I want to get the value of all the drop downs in my view

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/cb4599dd-d98f-4331-b7ae-56be77acb335%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Form not valid error

Adam Johnson-2
Hi!

I think you've found the wrong mailing list for this post. This mailing list is for the development of Django itself, not for support using Django. This means the discussions of bugs and features in Django itself, rather than in your code using it. People on this list are unlikely to answer your support query with their limited time and energy. Read more on the mailing lists at https://www.djangoproject.com/community/

For support, please use the django-users mailing list, or IRC #django on Freenode, or a site like Stack Overflow. There are people out there willing to help on those channels, but they might not respond if you don't ask your question well. Stack Overflow's question guide can help you frame it well: https://stackoverflow.com/help/how-to-ask .

Also if you haven't read it, please take a look at Django's Code of Conduct: https://www.djangoproject.com/conduct/ . These are our "ground rules" for working well as a community, and will help you get the most out of Django and our fantastic community.

Thanks for your understanding,

Adam

On Wed, 8 May 2019 at 10:00, Dimple Mathew <[hidden email]> wrote:
I am trying to pass data from a form to view, but form is not valid.

I have 3 drop-downs on this form on clicking on submit, if any relavant data is available in the database it should be loaded on the template. Basically this form is a set of filters that load data based on selection.

views.py

def mentioe(request):
emp_dd= request.user.username
flag=0
if request.method == 'POST':
    form = Management_Collector(request.POST or None)
    if form.is_valid():
        m_s = form.cleaned_data.get('month_start')
        m_e = form.cleaned_data.get('month_end')
        y = form.cleaned_data.get('process_select')

        mentione= mrg_bpo.objects.filter(Q(emp_id=emp_dd) & Q(month=m_s))

        if not mentione:
            messages.error(request, 'Data is not available for your selection please consider re-selecting.')
        else:
            messages.success(request, 'Search Result Displayed Below')
        return render(request, 'mentione.html', {'form': form, 'mentione': mentione})
    else:
        print(form.errors)
        print('some issue')


else:
    print('i go to else')
    form = Management_Collector()
return render(request, 'mentione.html', {'form': form})

forms.py class Management_Collector(forms.ModelForm):

class Meta:
    model = mrg_bpo
    fields = ['month','year','process_select']
    labels = {
        "month": _(""),
    }
    widget = {
        'month':forms.HiddenInput(),
        'year':forms.HiddenInput(),
    }

index.html

<form action="" method="POST">

                    {%csrf_token%}
<select class="form-control" id="month_start" name="month_start">

  {% for i in form.month %}
<option>{{ i }}</option>
{% endfor %}</select>


<select class="form-control" id="month_end" name="month_end" > <option>

</option>
 {% for i in form.month %}
<option>{{ i }}</option>
        {% endfor %}
         </select>

{{form.year}}
{{form.process_select}}
 <button type="submit" class="btn btn-success" id="btn">Submit</button>
</form>

I want to get the value of all the drop downs in my view

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/cb4599dd-d98f-4331-b7ae-56be77acb335%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM3ja%2BZhmpLWT-3LcgYSboWx8gGRG4pNs-gu6%3DO9LnNWUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.