Re: Form Validation for GET Request

2008-06-14 Thread [EMAIL PROTECTED]

I always use

if(len(request.GET)>0):
  form=TestForm(request.GET)
  if(form.is_valid()):
#process form
else:
  form=Testform()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread Bartek Gniado
Maybe because you actually have to pass `action`? ;)

Pass it through your form. Maybe my use of 'action' confused you with the
's action property. Not what I meant, sorry.

I didn't realize you had an actual form (Wait, why do you .. Ok, beyond the
point) but in this case you can just check for any value within your form
and see if it's True
If your form has a "name" field you could do: if request.GET.get('name'):
...

Your initial problem is when you load a page, that Is a GET request so
that's why it was going through.





On Fri, Jun 13, 2008 at 10:45 PM, ichbindev <[EMAIL PROTECTED]> wrote:

>
> This is what my template looks like:
>
> {{ form.as_table }}  table>
>
> This is what my view looks like:
>
> ...
> myform = MyForm()
> if request.method=="GET":
>myform = MyForm(request.GET)
> if request.GET.get('action') == True:
> if myform.is_valid():
>...
> ...
> return render_to_response ('template.html', {'form' : myform})
>
> When I first go to the page, requet.GET.get('action') is None. When I
> click the 'submit' button, again requet.GET.get('action') is None. I
> used HttpResponse to return requet.GET.get('action') as a string.
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread ichbindev

This is what my template looks like:

{{ form.as_table }} 

This is what my view looks like:

...
myform = MyForm()
if request.method=="GET":
myform = MyForm(request.GET)
if request.GET.get('action') == True:
if myform.is_valid():
...
...
return render_to_response ('template.html', {'form' : myform})

When I first go to the page, requet.GET.get('action') is None. When I
click the 'submit' button, again requet.GET.get('action') is None. I
used HttpResponse to return requet.GET.get('action') as a string.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread Bartek Gniado
If errors are showing when you first load the page then you need to check
that the user has actually completed an action before validating the form.

In this case, doing something like
if request.GET.get('action') == True:
   # your form validation here

In your links back to the system, simply add an ?action=true (or whatever)
and that'll fix your issue there.


On Fri, Jun 13, 2008 at 10:03 PM, ichbindev <[EMAIL PROTECTED]> wrote:

>
> The problem is when I use
>
> myform = MyForm(request.GET)
> if myform.is_valid():
> ...
>
> Any fields which are required have their error message activated on
> first visit to page. Also, any 'initial' value that I put in the forms
> is not shown.
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread ichbindev

The problem is when I use

myform = MyForm(request.GET)
if myform.is_valid():
...

Any fields which are required have their error message activated on
first visit to page. Also, any 'initial' value that I put in the forms
is not shown.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Validation for GET Request

2008-06-13 Thread Russell Keith-Magee

On Sat, Jun 14, 2008 at 9:05 AM, ichbindev <[EMAIL PROTECTED]> wrote:
>
> However, form.is_valid() is for POST only. Is there an is_valid() kind
> of thing for forms where method is GET so that data may be validated?

I don't know what gave you the idea that is_valid() is just for POST
data. There is nothing in the newforms framework that is tied
specifically to POST data. You can bind _any_ data to a form, whatever
the source.

Most of the examples you will see use POST data, because that's the
most common way to use forms. However, if you can call:

myform = MyForm(request.POST)
if myform.is_valid():
   ...

you could also call:

myform = MyForm(request.GET)
if myform.is_valid():
   ...

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Form Validation for GET Request

2008-06-13 Thread ichbindev

I am writing a report page where users get to enter data in a form and
based on it search results are provided. There are at least four
fields in the form and all are used in searching. We are not making
any changes to data, we should use GET instead of POST as form method.
Since this input is going to be used to search database, we need to
make sure it is valid before even thinking of sending it further.
However, form.is_valid() is for POST only. Is there an is_valid() kind
of thing for forms where method is GET so that data may be validated?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---