Do you really need to show the message for the remainder of the session? Or just when the page loads right after the user has successfully subscribed? in this case you could just delete the value after being "used":
if request.session.get('signed_up', True): form.thanks = True # delete 'signed_up' from session I'm not sure this meets your needs, but it's a suggestion :) Nuno On Mon, Mar 22, 2010 at 9:40 PM, grimmus <graham.col...@gmail.com> wrote: > Basically all i want to do is the following : > > Have a newsletter signup form. When the user signs up successfully the > area where the form was has a thanks message instead of the form. > > The form or thanks message is displayed on every page of the site, so > I thought using a session would be the best way handle whether to show > the form or the thanks message. > > Here is my form > > <form class="form subscribe" id="subscribe_form" method="post"> > <fieldset class="inlineElements"> > {% if form.errors %} > <p>Please enter a valid email address.</p> > {% endif %} > {% if form.thanks %} > <p>Thanks for signing up</p> > {% endif %} > {% if form.alreadyexists %} > <p>The email address already exists</p> > {% endif %} > {% if not form.thanks %} > <input type="text" class="textbox" name="email" > value="Email > address" onfocus="this.select()" /> > <input type="submit" id="mailinglist" class="button > submit" > value="Go"/> > {% endif %} > </fieldset> > </form> > > And my view > > if request.POST: > form = SignUp(request.POST) > > if form.is_valid(): > > email = request.POST.get('email', '') > > try: > entry = MailingList.objects.get(email=email) > > form.alreadyexists = True > > except (KeyError, MailingList.DoesNotExist): > > entry = MailingList() > entry.email = email > entry.date_added = datetime.now() > entry.save() > > request.session['signed_up'] = True > form.thanks = True > > return HttpResponseRedirect(request.get_full_path()) > > else: > print form.errors > > else: > > form = SignUp() > > t = loader.get_template('home/page.html') > c = RequestContext(request,{ > 'form':form, > }) > > if request.session.get('signed_up', True): > form.thanks = True > > return HttpResponse(t.render(c)) > > > Any help is greatly appreciated. > > On Mar 22, 3:13 pm, Bill Freeman <ke1g...@gmail.com> wrote: >> And if the user disables javascript, or kills the browser without >> normal exit, or loses >> his connection, or pulls the ethernet cable, or has a power failure? >> >> On Mon, Mar 22, 2010 at 10:06 AM, Wiiboy <jordon...@gmail.com> wrote: >> > Couldn't you use Javascript for this? For example, on the >> > onbeforeunload event, delete the sessionid cookie? >> >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "Django users" group. >> > To post to this group, send email to django-us...@googlegroups.com. >> > To unsubscribe from this group, send email to >> > django-users+unsubscr...@googlegroups.com. >> > For more options, visit this group >> > athttp://groups.google.com/group/django-users?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.