On 5 oct, 16:40, ydjango <[EMAIL PROTECTED]> wrote:
> I have more than one input submit button and want to know which one
> was clicked.
> Request.POST does not have that information for some reason.
>
> Using django 1.0 svn
>
> I would appreciate if you can point me to right resource.
> This is should be something very simple that I am missing.

Probably - but I have no cue about what's causing your problem.


I just did a quick test and it worked just fine. Here's the test:

# yadda/view.py
 from django.shortcuts import render_to_response

def form(request):
    context = dict(post=dict(), results=list())

    if request.POST:
        for k in request.POST:
            context['post'][k] = request.POST[k]

        for name in ('save', 'id_save', 'Save', 'cancel', 'id_cancel',
'Cancel'):
            context['results'].append(
                "request.POST.has_key('%s') == %s" % (name,
request.POST.has_key(name))
                )

    return render_to_response('yadda/form.html', context)

# templates/yadda/form.html
{% if results %}
<ul>
{% for r in results %}
<li>{{ r }}</li>
{% endfor %}
<ul>
{% endif %}

{% if post %}
<pre>{{ post|default:"???" }}</pre>
{% else %}
<b>no post</b><br />
{% endif %}

<form method='post' action=''>
<p>
<input type='submit' name='save' id='id_save' value='Save' />
</p>
<p>
<input type='submit' name='cancel' id='id_cancel' value='Cancel' />
</p>
</form>

# urls.py
from django.conf.urls.defaults import *
from yadda.views import form

urlpatterns = patterns('',
    url(r'^form/$', form),
)

Try running this in your project...


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

Reply via email to