If I have several forms on a page and a single view function for them, how do I determine which of them was submitted in the "if request.method == 'POST':" construct? -- Regards, Andriy Yurchuk
On each of the forms, add a hidden input element with a distinct value. Then check that value when you process the incoming form in the view. On Fri, Nov 4, 2011 at 10:58 AM, Andriy Yurchuk <ayurchuk@minuteware.net> wrote: > If I have several forms on a page and a single view function for them, > how do I determine which of them was submitted in the "if request.method > == 'POST':" construct? > > -- > Regards, > Andriy Yurchuk > > >
I'm kind of stuck with this. The Add button works as expected, but the Delete one does not. Clicking it does not give any result (no requests are sent). I'll appreciate if you could take a look at my code here: http://pastebin.com/732ttgRN There are my template and the view function. Thanks ahead. --- Regards, Andriy Yurchuk On Fri, 4 Nov 2011 11:36:38 -0500, Andy Wilson wrote: > On each of the forms, add a hidden input element with a distinct > value. Then check that value when you process the incoming form in > the > view. > > > On Fri, Nov 4, 2011 at 10:58 AM, Andriy Yurchuk > <ayurchuk@minuteware.net> wrote: >> If I have several forms on a page and a single view function for >> them, >> how do I determine which of them was submitted in the "if >> request.method >> == 'POST':" construct? >> >> -- >> Regards, >> Andriy Yurchuk >> >> >>
Looks like the form that starts at line 20 is not being closed before the form at line 44 begins. And then there are two closing form tags at the end. Then your delete submit is outside of all of them so it isn't associated with any form and that's why nothing happens when you click it. On Fri, Nov 4, 2011 at 3:43 PM, Andriy Yurchuk <ayurchuk@minuteware.net> wrote: > I'm kind of stuck with this. The Add button works as expected, but the > Delete one does not. Clicking it does not give any result (no requests > are sent). I'll appreciate if you could take a look at my code here: > http://pastebin.com/732ttgRN There are my template and the view > function. > > Thanks ahead. > > --- > Regards, > Andriy Yurchuk > > On Fri, 4 Nov 2011 11:36:38 -0500, Andy Wilson wrote: >> On each of the forms, add a hidden input element with a distinct >> value. Then check that value when you process the incoming form in >> the >> view. >> >> >> On Fri, Nov 4, 2011 at 10:58 AM, Andriy Yurchuk >> <ayurchuk@minuteware.net> wrote: >>> If I have several forms on a page and a single view function for >>> them, >>> how do I determine which of them was submitted in the "if >>> request.method >>> == 'POST':" construct? >>> >>> -- >>> Regards, >>> Andriy Yurchuk >>> >>> >>> > >
Form tags are OK, but the Delete button indeed was outside of the form. Thanks for taking a look! --- Regards, Andriy Yurchuk On Fri, 4 Nov 2011 15:55:12 -0500, Andy Wilson wrote: > Looks like the form that starts at line 20 is not being closed before > the form at line 44 begins. And then there are two closing form tags > at the end. Then your delete submit is outside of all of them so it > isn't associated with any form and that's why nothing happens when > you > click it. > > > On Fri, Nov 4, 2011 at 3:43 PM, Andriy Yurchuk > <ayurchuk@minuteware.net> wrote: >> I'm kind of stuck with this. The Add button works as expected, but >> the >> Delete one does not. Clicking it does not give any result (no >> requests >> are sent). I'll appreciate if you could take a look at my code here: >> http://pastebin.com/732ttgRN There are my template and the view >> function. >> >> Thanks ahead. >> >> --- >> Regards, >> Andriy Yurchuk >> >> On Fri, 4 Nov 2011 11:36:38 -0500, Andy Wilson wrote: >>> On each of the forms, add a hidden input element with a distinct >>> value. Then check that value when you process the incoming form in >>> the >>> view. >>> >>> >>> On Fri, Nov 4, 2011 at 10:58 AM, Andriy Yurchuk >>> <ayurchuk@minuteware.net> wrote: >>>> If I have several forms on a page and a single view function for >>>> them, >>>> how do I determine which of them was submitted in the "if >>>> request.method >>>> == 'POST':" construct? >>>> >>>> -- >>>> Regards, >>>> Andriy Yurchuk >>>> >>>> >>>> >> >>
May be you solved it already, but in your code the delete button is disabled, thus doing nothing as you already said: <input class=delete type=submit value=Delete disabled> I would also suggest to use some kind of Form/widget library to avoid redundant markup regards, Oliver On 04.11.2011 22:04, Andriy Yurchuk wrote: > Form tags are OK, but the Delete button indeed was outside of the form. > Thanks for taking a look! > > --- > Regards, > Andriy Yurchuk > > On Fri, 4 Nov 2011 15:55:12 -0500, Andy Wilson wrote: >> Looks like the form that starts at line 20 is not being closed before >> the form at line 44 begins. And then there are two closing form tags >> at the end. Then your delete submit is outside of all of them so it >> isn't associated with any form and that's why nothing happens when >> you >> click it. >> >> >> On Fri, Nov 4, 2011 at 3:43 PM, Andriy Yurchuk >> <ayurchuk@minuteware.net> wrote: >>> I'm kind of stuck with this. The Add button works as expected, but >>> the >>> Delete one does not. Clicking it does not give any result (no >>> requests >>> are sent). I'll appreciate if you could take a look at my code here: >>> http://pastebin.com/732ttgRN There are my template and the view >>> function. >>> >>> Thanks ahead. >>> >>> --- >>> Regards, >>> Andriy Yurchuk >>> >>> On Fri, 4 Nov 2011 11:36:38 -0500, Andy Wilson wrote: >>>> On each of the forms, add a hidden input element with a distinct >>>> value. Then check that value when you process the incoming form in >>>> the >>>> view. >>>> >>>> >>>> On Fri, Nov 4, 2011 at 10:58 AM, Andriy Yurchuk >>>> <ayurchuk@minuteware.net> wrote: >>>>> If I have several forms on a page and a single view function for >>>>> them, >>>>> how do I determine which of them was submitted in the "if >>>>> request.method >>>>> == 'POST':" construct? >>>>> >>>>> -- >>>>> Regards, >>>>> Andriy Yurchuk >>>>> >>>>> >>>>> >>> >>> >