0

I don't usually have a lot of trouble with django form submission, but i can't seem to figure out what am not doing right for my code to work. Done some reading here at stackoverflow but no luck.

In my template, i define a form that is rendered within a twitter bootstrap modal,

<div class="modal-body">
 <form method="post" action="{%url 'item_order' item.id %}">
   <input class="btn btn-large btn-success" type="submit" name="submit" value="add to order"/>
 </form>

In the form header, i want to explicitly have the form submit to this view,

def show_item(request,id):
    a = Item.objects.get(pk=id)
    if request.method == 'POST':
        form = partial_order_item_form()
        final_form = form(request.POST)
        # check validation of posted data
        if final_form.is_valid():
            order.add_to_order(request,a)
            url =urlresolvers.reverse('order_index',kwargs={'id':a.id})
            # redirect
            return HttpResponseRedirect(url)

urls.py

url(r'^item/(?P<id>\d+)/$',show_item, name="item_order")

To my suprise, the form will not submit to this view, in fact it will not do anything at all. This beats my understanding, i thought if i have explicitly set the action in the form header, it would work as i intend it to.

What am not doing right? Links are appreciated as well.

Edit Inspecting with firebug as pointed out by @danihp, i have learnt that when the browser renders the page it closes the form before rendering all django template logic i want it to.

<form method="post" action="orders/item/2"></form>
<input class="btn btn-large btn-success" type="submit" name="submit" value="add to order"/>

so when i submit nothing happens because the input element is not in the form.

SOLVED

Check out my answer.

Suziemac Tani
  • 455
  • 9
  • 23

1 Answers1

0

Looking aroung i found the same problem and solution. It happens my html markup was poorly written, the mentioned problem and solution helped figure it out.

Community
  • 1
  • 1
Suziemac Tani
  • 455
  • 9
  • 23