Re: how to handle forms with more than submit button

2007-08-02 Thread Kenneth Gonsalves


On 03-Aug-07, at 10:12 AM, Kenneth Gonsalves wrote:

>
>
> On 03-Aug-07, at 8:06 AM, james_027 wrote:
>
>>> create different URLs (and thus different views) for the different
>>> buttons and then redirect to wherever you want to go.
>>>
>>
>> How do I create a different URL for different buttons but under one
>> form?
>
> each submit button has a name - say 'add', 'edit', 'delete', so write
> code like:
> if 'add' in request.POST.keys():
>   do something
> if 'add' in request.POST.keys():
>   do something

oops s/add/delete/

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread Kenneth Gonsalves


On 03-Aug-07, at 8:06 AM, james_027 wrote:

>> create different URLs (and thus different views) for the different
>> buttons and then redirect to wherever you want to go.
>>
>
> How do I create a different URL for different buttons but under one
> form?

each submit button has a name - say 'add', 'edit', 'delete', so write  
code like:
if 'add' in request.POST.keys():
  do something
if 'add' in request.POST.keys():
  do something


-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/web/



--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread Doug B

context_dict.update(button1_helper())

Opps, forgot to actually call button1_helper.  Sorry, need sleep :)


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread Doug B

> thanks doug, this is what I did, but I am not comfortable with it.
> those two button do different things, and if they're under one method
> on the views it could be ugly, what if I have 4 or 5 submit buttons?

Keep in mind there is nothing keeping one view from calling another.

def button1view(request):
   stuff

def view1(request):
   if request.POST and request.POST.has_key('button1'):
   return button1view(request)

More often I find myself doing helper functions to keep the logic
straight.

def button1_helper():
return {'button1': True}

def view1(request):
   context_dict={}
   if request.POST:
   if request.POST.has_key('button1'):
   context_dict.update(button1_helper)
   ...


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread [EMAIL PROTECTED]

Well... that's how I've been doing it anyway :)

On Aug 2, 11:15 pm, james_027 <[EMAIL PROTECTED]> wrote:
> hi,
>
> On Aug 3, 11:12 am, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > Oh... forgot the semicolons after .submit(); but you get the picture
>
> thanks carole, yes I the picture. so its about javascript not
> django ...
>
> cheers,
> james


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread james_027

Hi,

On Aug 3, 11:21 am, Doug B <[EMAIL PROTECTED]> wrote:
> As far as I know a form submits to a single url via the action=?
> specifier.  That's just the way an html form works.  Each submit
> button that is part of the form is going to post to the action url in
> the form.  You can override with javascript, but that doesn't make
> much sense unless you're doing ajax or something.
>
> You CAN check to see which submit button was used in the view, and
> make logic decisions accordingly.  Just make sure you name your submit
> buttons and check which is in request.POST and make logic decisions
> from there.
>
> in template
> 
> 
>
> then in view
> if request.POST:
> if request.POST.has_key('button1'):
> do button 1 stuff
> elif request.POST.has_key('button2'):
> do button 2 stuff

thanks doug, this is what I did, but I am not comfortable with it.
those two button do different things, and if they're under one method
on the views it could be ugly, what if I have 4 or 5 submit buttons?

any other sugguestions?

thanks
james


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread Doug B

As far as I know a form submits to a single url via the action=?
specifier.  That's just the way an html form works.  Each submit
button that is part of the form is going to post to the action url in
the form.  You can override with javascript, but that doesn't make
much sense unless you're doing ajax or something.

You CAN check to see which submit button was used in the view, and
make logic decisions accordingly.  Just make sure you name your submit
buttons and check which is in request.POST and make logic decisions
from there.

in template




then in view
if request.POST:
if request.POST.has_key('button1'):
do button 1 stuff
elif request.POST.has_key('button2'):
do button 2 stuff




--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread james_027

hi,

On Aug 3, 11:12 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Oh... forgot the semicolons after .submit(); but you get the picture
>

thanks carole, yes I the picture. so its about javascript not
django ...

cheers,
james


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread [EMAIL PROTECTED]

Oh... forgot the semicolons after .submit(); but you get the picture

On Aug 2, 11:11 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Something like this...
>
> 
> function submitFunctionA()
> {
>document.getElementById('myform').action = "someurl";
>document.getElementById('myform').submit()
>
> }
>
> function submitFunctionB()
> {
>document.getElementById('myform').action = "someotherurl";
>document.getElementById('myform').submit()}
>
> 
> 
> .
> .
> some form fields
> .
> .
> First Save Button
> .
> .
> some other stuff...
> Second Save Button
> 
>
> On Aug 2, 10:36 pm, james_027 <[EMAIL PROTECTED]> wrote:
>
> > hi
>
> > > create different URLs (and thus different views) for the different
> > > buttons and then redirect to wherever you want to go.
>
> > How do I create a different URL for different buttons but under one
> > form?
>
> > Thanks
> > james


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread [EMAIL PROTECTED]

Something like this...


function submitFunctionA()
{
   document.getElementById('myform').action = "someurl";
   document.getElementById('myform').submit()
}

function submitFunctionB()
{
   document.getElementById('myform').action = "someotherurl";
   document.getElementById('myform').submit()
}


.
.
some form fields
.
.
First Save Button
.
.
some other stuff...
Second Save Button


On Aug 2, 10:36 pm, james_027 <[EMAIL PROTECTED]> wrote:
> hi
>
> > create different URLs (and thus different views) for the different
> > buttons and then redirect to wherever you want to go.
>
> How do I create a different URL for different buttons but under one
> form?
>
> Thanks
> james


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread james_027

hi


> create different URLs (and thus different views) for the different
> buttons and then redirect to wherever you want to go.
>

How do I create a different URL for different buttons but under one
form?

Thanks
james


--~--~-~--~~~---~--~~
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: how to handle forms with more than submit button

2007-08-02 Thread Lucky B

create different URLs (and thus different views) for the different
buttons and then redirect to wherever you want to go.

On Aug 2, 10:13 pm, james_027 <[EMAIL PROTECTED]> wrote:
> Hi,
>
> How do I handle this situation wherein I want different submit button
> to call different method on the views. I feel that calling the same
> method on views for all the submit button on a form is not good, as
> you'll make the distinction of what to do inside the method...
>
> Thanks
> james


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



how to handle forms with more than submit button

2007-08-02 Thread james_027

Hi,

How do I handle this situation wherein I want different submit button
to call different method on the views. I feel that calling the same
method on views for all the submit button on a form is not good, as
you'll make the distinction of what to do inside the method...

Thanks
james


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---