4

I am working with Satchmo and am wondering for the newsletter subscription, how to make it so when people sign up, they are automatically subscribed to the newsletter. I found this line of code in forms.py:

newsletter = forms.BooleanField(label=_('Receive Daily Deals'),
    widget=forms.CheckboxInput(), required=False)

I am assuming that in the widget there, I can add something to make it automatically be true and hidden.

ljs.dev
  • 4,449
  • 3
  • 47
  • 80
Wesley
  • 65
  • 1
  • 3

2 Answers2

6
newsletter = forms.BooleanField(label=_('Receive Daily Deals'),
    widget=forms.HiddenInput(), required=False, initial=True)
Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48
5

You can make checkbox hidden with adding a class to element shown as below:

// css
// .hidden { display: none;}

newsletter = forms.BooleanField(
    label=_('Receive Daily Deals'),
    widget=forms.CheckboxInput(attrs={'class': 'hidden'}), 
    required=False, 
    initial=True
)
Mesut Tasci
  • 2,970
  • 1
  • 30
  • 36