Note that there are some explanatory texts on larger screens.

plurals
  1. POParameter not passing through form?
    primarykey
    data
    text
    <p>I'm trying to work with the django form validation walkthrough that they have <a href="https://docs.djangoproject.com/en/dev/ref/forms/validation/" rel="nofollow">here</a></p> <p>However, I seem to be getting stuck. It seem that one of my parameters (recipients) isn't being passed through, even though the others are. </p> <p>Here is my html form:</p> <pre><code>&lt;form action= "receiver" method="post" &gt; {% csrf_token %} &lt;p&gt;&lt;label for="id_subject"&gt;Subject:&lt;/label&gt; &lt;input id="id_subject" type="text" name="subject" maxlength="100" /&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="id_message"&gt;Message:&lt;/label&gt; &lt;input type="text" name="message" id="id_message" /&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="id_sender"&gt;Sender:&lt;/label&gt; &lt;input type="text" name="sender" id="id_sender" /&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="id_recipients"&gt;Recipients:&lt;/label&gt; &lt;input type="text" name="recipients" id="id_recipients" /&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="id_cc_myself"&gt;Cc myself:&lt;/label&gt; &lt;input type="checkbox" name="cc_myself" id="id_cc_myself" /&gt;&lt;/p&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>Here is the relevant model class in models.py:</p> <pre><code>class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() sender = forms.EmailField() recipients = MultiEmailField(required=True) cc_myself = forms.BooleanField(required=False) </code></pre> <p>and here is the associated view: </p> <pre><code>def reciever(request): form = ContactForm(request.POST) # A form bound to the POST data print form if request.method == 'POST': if form.is_valid(): subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] sender = form.cleaned_data['sender'] cc_myself = form.cleaned_data['cc_myself'] recipients = form.cleaned_data['recipients'] template = loader.get_template('helloworld/receiver.html') context = RequestContext(request,{ 'subject':subject, 'sender':sender, 'message': message, 'cc_myself': cc_myself, 'recipients': recipients, }) return HttpResponse(template.render(context)) else: context = RequestContext(request,{ 'form': form, }) template = loader.get_template('helloworld/wrong.html') return HttpResponse(template.render(context)) </code></pre> <p>I don't get too much into the view, I can see from my print form that the request is invalid with the following output:</p> <pre><code>&lt;tr&gt;&lt;th&gt;&lt;label for="id_subject"&gt;Subject:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id_subject" maxlength="100" name="subject" type="text" value="slkj" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;th&gt;&lt;label for="id_message"&gt;Message:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id_message" name="message" type="text" value="lkjqw" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;th&gt;&lt;label for="id_sender"&gt;Sender:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id_sender" name="sender" type="text" value="ij@aol.com" /&gt;&lt;/td&gt;&lt;/tr&gt; **&lt;tr&gt;&lt;th&gt;&lt;label for="id_recipients"&gt;Recipients:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;input id="id_recipients" name="recipients" type="text" /&gt;&lt;/td&gt;&lt;/tr&gt;** &lt;tr&gt;&lt;th&gt;&lt;label for="id_cc_myself"&gt;Cc myself:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id_cc_myself" name="cc_myself" type="checkbox" /&gt;&lt;/td&gt;&lt;/tr&gt; </code></pre> <p>So for some reason, even though I do enter info into the form box (fake@aol.com), it doesn't seem to be passing through the form, and I'm not quite sure why.</p> <p>Edit: sorry, I forgot an important part. I also added a custom class to the model.py as per the tutorial's instructions:</p> <pre><code>class MultiEmailField(forms.Field): def to_python(self, value): "Normalize data to a list of strings." # Return an empty list if no input was given. if not value: return [] return value.split(',') def validate(self, value): "Check if value consists only of valid emails." # Use the parent's handling of required fields, etc. super(MultiEmailField, self).validate(value) for email in value: validate_email(email) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload