Django: Internet Explorer POSTs an empty form












0














I have a ModelForm that works perfectly for FireFox and Chrome, but for some reason, whenever anybody submits the form with IE, the server just receives the form with empty values. I've verified this by printing the submitted values in form.is_valid() (as you can see below).



Here is my code:



template.html:



<form id="tracking_form" action="/tracking/{{ view.person.id }}" method="POST">
{% csrf_token %}
{{ form.person }}
<input type="submit" class="btn btn-default" value="Add Data" style="width: 190px;">
</form>


forms.py:



class TrackingForm(forms.ModelForm):

def __init__(self, active_student=None, *args, **kwargs):
super(TrackingForm, self ).__init__(*args, **kwargs)
points_dict = {'class': 'weekday_points', 'min': 0, 'max': 100 }
arrived_dict = { 'class': 'not_required' }


for field in self.fields.values():
field.widget.attrs['form'] = 'tracking_form'
field.widget.attrs['class'] = 'form_field'
field.required = False

self.fields['monday_points'].widget.attrs.update(points_dict)
self.fields['tuesday_points'].widget.attrs.update(points_dict)
self.fields['wednesday_points'].widget.attrs.update(points_dict)
self.fields['thursday_points'].widget.attrs.update(points_dict)
self.fields['friday_points'].widget.attrs.update(points_dict)
self.fields['monday_arrived'].widget.attrs.update(arrived_dict)
self.fields['tuesday_arrived'].widget.attrs.update(arrived_dict)
self.fields['wednesday_arrived'].widget.attrs.update(arrived_dict)
self.fields['thursday_arrived'].widget.attrs.update(arrived_dict)
self.fields['friday_arrived'].widget.attrs.update(arrived_dict)

def is_valid(self):
# This is just here to print the values server receives
for name, field in self.fields.items():

if field.disabled:
value = self.get_initial_for_field(field, name)
else:
value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
print(name, ":", field.clean(value))

valid = super(TrackingForm, self).is_valid()

return valid


class Meta:

model = models.Tracking
exclude = ('person',)


This is the log when submitting the form with FireFox:



2018-11-16 02:23:15 week : 3
2018-11-16 02:23:15 term : 4
2018-11-16 02:23:15 year : 2018
2018-11-16 02:23:15 b1 : fasd
2018-11-16 02:23:15 b2 : asdfsad
2018-11-16 02:23:15 monday_points : 0
2018-11-16 02:23:15 monday_attended : 1
2018-11-16 02:23:15 monday_arrived : 09:00:00
2018-11-16 02:23:15 tuesday_points : 0
2018-11-16 02:23:15 tuesday_attended : 1
2018-11-16 02:23:15 tuesday_arrived : 09:00:00
2018-11-16 02:23:15 wednesday_points : 0
2018-11-16 02:23:15 wednesday_attended : 1
2018-11-16 02:23:15 wednesday_arrived : 10:30:00
2018-11-16 02:23:15 thursday_points : 0
2018-11-16 02:23:15 thursday_attended : 1
2018-11-16 02:23:15 thursday_arrived : 09:00:00
2018-11-16 02:23:15 friday_points : 0
2018-11-16 02:23:15 friday_attended : 1
2018-11-16 02:23:15 friday_arrived : 09:00:00


And this is the log from submitting the same form in IE:



2018-11-16 02:23:41 week : 
2018-11-16 02:23:41 term :
2018-11-16 02:23:41 year :
2018-11-16 02:23:41 b1 :
2018-11-16 02:23:41 b2 :
2018-11-16 02:23:41 monday_points : None
2018-11-16 02:23:41 monday_attended :
2018-11-16 02:23:41 monday_arrived :
2018-11-16 02:23:41 tuesday_points : None
2018-11-16 02:23:41 tuesday_attended :
2018-11-16 02:23:41 tuesday_arrived :
2018-11-16 02:23:41 wednesday_points : None
2018-11-16 02:23:41 wednesday_attended :
2018-11-16 02:23:41 wednesday_arrived :
2018-11-16 02:23:41 thursday_points : None
2018-11-16 02:23:41 thursday_attended :
2018-11-16 02:23:41 thursday_arrived :
2018-11-16 02:23:41 friday_points : None
2018-11-16 02:23:41 friday_attended :
2018-11-16 02:23:41 friday_arrived :









share|improve this question





























    0














    I have a ModelForm that works perfectly for FireFox and Chrome, but for some reason, whenever anybody submits the form with IE, the server just receives the form with empty values. I've verified this by printing the submitted values in form.is_valid() (as you can see below).



    Here is my code:



    template.html:



    <form id="tracking_form" action="/tracking/{{ view.person.id }}" method="POST">
    {% csrf_token %}
    {{ form.person }}
    <input type="submit" class="btn btn-default" value="Add Data" style="width: 190px;">
    </form>


    forms.py:



    class TrackingForm(forms.ModelForm):

    def __init__(self, active_student=None, *args, **kwargs):
    super(TrackingForm, self ).__init__(*args, **kwargs)
    points_dict = {'class': 'weekday_points', 'min': 0, 'max': 100 }
    arrived_dict = { 'class': 'not_required' }


    for field in self.fields.values():
    field.widget.attrs['form'] = 'tracking_form'
    field.widget.attrs['class'] = 'form_field'
    field.required = False

    self.fields['monday_points'].widget.attrs.update(points_dict)
    self.fields['tuesday_points'].widget.attrs.update(points_dict)
    self.fields['wednesday_points'].widget.attrs.update(points_dict)
    self.fields['thursday_points'].widget.attrs.update(points_dict)
    self.fields['friday_points'].widget.attrs.update(points_dict)
    self.fields['monday_arrived'].widget.attrs.update(arrived_dict)
    self.fields['tuesday_arrived'].widget.attrs.update(arrived_dict)
    self.fields['wednesday_arrived'].widget.attrs.update(arrived_dict)
    self.fields['thursday_arrived'].widget.attrs.update(arrived_dict)
    self.fields['friday_arrived'].widget.attrs.update(arrived_dict)

    def is_valid(self):
    # This is just here to print the values server receives
    for name, field in self.fields.items():

    if field.disabled:
    value = self.get_initial_for_field(field, name)
    else:
    value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
    print(name, ":", field.clean(value))

    valid = super(TrackingForm, self).is_valid()

    return valid


    class Meta:

    model = models.Tracking
    exclude = ('person',)


    This is the log when submitting the form with FireFox:



    2018-11-16 02:23:15 week : 3
    2018-11-16 02:23:15 term : 4
    2018-11-16 02:23:15 year : 2018
    2018-11-16 02:23:15 b1 : fasd
    2018-11-16 02:23:15 b2 : asdfsad
    2018-11-16 02:23:15 monday_points : 0
    2018-11-16 02:23:15 monday_attended : 1
    2018-11-16 02:23:15 monday_arrived : 09:00:00
    2018-11-16 02:23:15 tuesday_points : 0
    2018-11-16 02:23:15 tuesday_attended : 1
    2018-11-16 02:23:15 tuesday_arrived : 09:00:00
    2018-11-16 02:23:15 wednesday_points : 0
    2018-11-16 02:23:15 wednesday_attended : 1
    2018-11-16 02:23:15 wednesday_arrived : 10:30:00
    2018-11-16 02:23:15 thursday_points : 0
    2018-11-16 02:23:15 thursday_attended : 1
    2018-11-16 02:23:15 thursday_arrived : 09:00:00
    2018-11-16 02:23:15 friday_points : 0
    2018-11-16 02:23:15 friday_attended : 1
    2018-11-16 02:23:15 friday_arrived : 09:00:00


    And this is the log from submitting the same form in IE:



    2018-11-16 02:23:41 week : 
    2018-11-16 02:23:41 term :
    2018-11-16 02:23:41 year :
    2018-11-16 02:23:41 b1 :
    2018-11-16 02:23:41 b2 :
    2018-11-16 02:23:41 monday_points : None
    2018-11-16 02:23:41 monday_attended :
    2018-11-16 02:23:41 monday_arrived :
    2018-11-16 02:23:41 tuesday_points : None
    2018-11-16 02:23:41 tuesday_attended :
    2018-11-16 02:23:41 tuesday_arrived :
    2018-11-16 02:23:41 wednesday_points : None
    2018-11-16 02:23:41 wednesday_attended :
    2018-11-16 02:23:41 wednesday_arrived :
    2018-11-16 02:23:41 thursday_points : None
    2018-11-16 02:23:41 thursday_attended :
    2018-11-16 02:23:41 thursday_arrived :
    2018-11-16 02:23:41 friday_points : None
    2018-11-16 02:23:41 friday_attended :
    2018-11-16 02:23:41 friday_arrived :









    share|improve this question



























      0












      0








      0







      I have a ModelForm that works perfectly for FireFox and Chrome, but for some reason, whenever anybody submits the form with IE, the server just receives the form with empty values. I've verified this by printing the submitted values in form.is_valid() (as you can see below).



      Here is my code:



      template.html:



      <form id="tracking_form" action="/tracking/{{ view.person.id }}" method="POST">
      {% csrf_token %}
      {{ form.person }}
      <input type="submit" class="btn btn-default" value="Add Data" style="width: 190px;">
      </form>


      forms.py:



      class TrackingForm(forms.ModelForm):

      def __init__(self, active_student=None, *args, **kwargs):
      super(TrackingForm, self ).__init__(*args, **kwargs)
      points_dict = {'class': 'weekday_points', 'min': 0, 'max': 100 }
      arrived_dict = { 'class': 'not_required' }


      for field in self.fields.values():
      field.widget.attrs['form'] = 'tracking_form'
      field.widget.attrs['class'] = 'form_field'
      field.required = False

      self.fields['monday_points'].widget.attrs.update(points_dict)
      self.fields['tuesday_points'].widget.attrs.update(points_dict)
      self.fields['wednesday_points'].widget.attrs.update(points_dict)
      self.fields['thursday_points'].widget.attrs.update(points_dict)
      self.fields['friday_points'].widget.attrs.update(points_dict)
      self.fields['monday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['tuesday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['wednesday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['thursday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['friday_arrived'].widget.attrs.update(arrived_dict)

      def is_valid(self):
      # This is just here to print the values server receives
      for name, field in self.fields.items():

      if field.disabled:
      value = self.get_initial_for_field(field, name)
      else:
      value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
      print(name, ":", field.clean(value))

      valid = super(TrackingForm, self).is_valid()

      return valid


      class Meta:

      model = models.Tracking
      exclude = ('person',)


      This is the log when submitting the form with FireFox:



      2018-11-16 02:23:15 week : 3
      2018-11-16 02:23:15 term : 4
      2018-11-16 02:23:15 year : 2018
      2018-11-16 02:23:15 b1 : fasd
      2018-11-16 02:23:15 b2 : asdfsad
      2018-11-16 02:23:15 monday_points : 0
      2018-11-16 02:23:15 monday_attended : 1
      2018-11-16 02:23:15 monday_arrived : 09:00:00
      2018-11-16 02:23:15 tuesday_points : 0
      2018-11-16 02:23:15 tuesday_attended : 1
      2018-11-16 02:23:15 tuesday_arrived : 09:00:00
      2018-11-16 02:23:15 wednesday_points : 0
      2018-11-16 02:23:15 wednesday_attended : 1
      2018-11-16 02:23:15 wednesday_arrived : 10:30:00
      2018-11-16 02:23:15 thursday_points : 0
      2018-11-16 02:23:15 thursday_attended : 1
      2018-11-16 02:23:15 thursday_arrived : 09:00:00
      2018-11-16 02:23:15 friday_points : 0
      2018-11-16 02:23:15 friday_attended : 1
      2018-11-16 02:23:15 friday_arrived : 09:00:00


      And this is the log from submitting the same form in IE:



      2018-11-16 02:23:41 week : 
      2018-11-16 02:23:41 term :
      2018-11-16 02:23:41 year :
      2018-11-16 02:23:41 b1 :
      2018-11-16 02:23:41 b2 :
      2018-11-16 02:23:41 monday_points : None
      2018-11-16 02:23:41 monday_attended :
      2018-11-16 02:23:41 monday_arrived :
      2018-11-16 02:23:41 tuesday_points : None
      2018-11-16 02:23:41 tuesday_attended :
      2018-11-16 02:23:41 tuesday_arrived :
      2018-11-16 02:23:41 wednesday_points : None
      2018-11-16 02:23:41 wednesday_attended :
      2018-11-16 02:23:41 wednesday_arrived :
      2018-11-16 02:23:41 thursday_points : None
      2018-11-16 02:23:41 thursday_attended :
      2018-11-16 02:23:41 thursday_arrived :
      2018-11-16 02:23:41 friday_points : None
      2018-11-16 02:23:41 friday_attended :
      2018-11-16 02:23:41 friday_arrived :









      share|improve this question















      I have a ModelForm that works perfectly for FireFox and Chrome, but for some reason, whenever anybody submits the form with IE, the server just receives the form with empty values. I've verified this by printing the submitted values in form.is_valid() (as you can see below).



      Here is my code:



      template.html:



      <form id="tracking_form" action="/tracking/{{ view.person.id }}" method="POST">
      {% csrf_token %}
      {{ form.person }}
      <input type="submit" class="btn btn-default" value="Add Data" style="width: 190px;">
      </form>


      forms.py:



      class TrackingForm(forms.ModelForm):

      def __init__(self, active_student=None, *args, **kwargs):
      super(TrackingForm, self ).__init__(*args, **kwargs)
      points_dict = {'class': 'weekday_points', 'min': 0, 'max': 100 }
      arrived_dict = { 'class': 'not_required' }


      for field in self.fields.values():
      field.widget.attrs['form'] = 'tracking_form'
      field.widget.attrs['class'] = 'form_field'
      field.required = False

      self.fields['monday_points'].widget.attrs.update(points_dict)
      self.fields['tuesday_points'].widget.attrs.update(points_dict)
      self.fields['wednesday_points'].widget.attrs.update(points_dict)
      self.fields['thursday_points'].widget.attrs.update(points_dict)
      self.fields['friday_points'].widget.attrs.update(points_dict)
      self.fields['monday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['tuesday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['wednesday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['thursday_arrived'].widget.attrs.update(arrived_dict)
      self.fields['friday_arrived'].widget.attrs.update(arrived_dict)

      def is_valid(self):
      # This is just here to print the values server receives
      for name, field in self.fields.items():

      if field.disabled:
      value = self.get_initial_for_field(field, name)
      else:
      value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
      print(name, ":", field.clean(value))

      valid = super(TrackingForm, self).is_valid()

      return valid


      class Meta:

      model = models.Tracking
      exclude = ('person',)


      This is the log when submitting the form with FireFox:



      2018-11-16 02:23:15 week : 3
      2018-11-16 02:23:15 term : 4
      2018-11-16 02:23:15 year : 2018
      2018-11-16 02:23:15 b1 : fasd
      2018-11-16 02:23:15 b2 : asdfsad
      2018-11-16 02:23:15 monday_points : 0
      2018-11-16 02:23:15 monday_attended : 1
      2018-11-16 02:23:15 monday_arrived : 09:00:00
      2018-11-16 02:23:15 tuesday_points : 0
      2018-11-16 02:23:15 tuesday_attended : 1
      2018-11-16 02:23:15 tuesday_arrived : 09:00:00
      2018-11-16 02:23:15 wednesday_points : 0
      2018-11-16 02:23:15 wednesday_attended : 1
      2018-11-16 02:23:15 wednesday_arrived : 10:30:00
      2018-11-16 02:23:15 thursday_points : 0
      2018-11-16 02:23:15 thursday_attended : 1
      2018-11-16 02:23:15 thursday_arrived : 09:00:00
      2018-11-16 02:23:15 friday_points : 0
      2018-11-16 02:23:15 friday_attended : 1
      2018-11-16 02:23:15 friday_arrived : 09:00:00


      And this is the log from submitting the same form in IE:



      2018-11-16 02:23:41 week : 
      2018-11-16 02:23:41 term :
      2018-11-16 02:23:41 year :
      2018-11-16 02:23:41 b1 :
      2018-11-16 02:23:41 b2 :
      2018-11-16 02:23:41 monday_points : None
      2018-11-16 02:23:41 monday_attended :
      2018-11-16 02:23:41 monday_arrived :
      2018-11-16 02:23:41 tuesday_points : None
      2018-11-16 02:23:41 tuesday_attended :
      2018-11-16 02:23:41 tuesday_arrived :
      2018-11-16 02:23:41 wednesday_points : None
      2018-11-16 02:23:41 wednesday_attended :
      2018-11-16 02:23:41 wednesday_arrived :
      2018-11-16 02:23:41 thursday_points : None
      2018-11-16 02:23:41 thursday_attended :
      2018-11-16 02:23:41 thursday_arrived :
      2018-11-16 02:23:41 friday_points : None
      2018-11-16 02:23:41 friday_attended :
      2018-11-16 02:23:41 friday_arrived :






      python django forms internet-explorer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 at 3:50









      Selcuk

      26.1k75368




      26.1k75368










      asked Nov 16 at 3:05









      Sam

      5961723




      5961723
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I fixed it. It wasn't really clear from the code I posted, but the form had most of the inputs outside the tags. IE, apparently, can't figure out that those tags belong to the form. I fixed it by placing the form tags around all of the input tags. Another solution might be to use the form attribute for input tags:



          <form id="myform">
          <input id="something" type="text">
          </form>

          <button form="myform" type="submit">Submit that form over there</button>


          But I haven't verified this will work.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330835%2fdjango-internet-explorer-posts-an-empty-form%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I fixed it. It wasn't really clear from the code I posted, but the form had most of the inputs outside the tags. IE, apparently, can't figure out that those tags belong to the form. I fixed it by placing the form tags around all of the input tags. Another solution might be to use the form attribute for input tags:



            <form id="myform">
            <input id="something" type="text">
            </form>

            <button form="myform" type="submit">Submit that form over there</button>


            But I haven't verified this will work.






            share|improve this answer


























              1














              I fixed it. It wasn't really clear from the code I posted, but the form had most of the inputs outside the tags. IE, apparently, can't figure out that those tags belong to the form. I fixed it by placing the form tags around all of the input tags. Another solution might be to use the form attribute for input tags:



              <form id="myform">
              <input id="something" type="text">
              </form>

              <button form="myform" type="submit">Submit that form over there</button>


              But I haven't verified this will work.






              share|improve this answer
























                1












                1








                1






                I fixed it. It wasn't really clear from the code I posted, but the form had most of the inputs outside the tags. IE, apparently, can't figure out that those tags belong to the form. I fixed it by placing the form tags around all of the input tags. Another solution might be to use the form attribute for input tags:



                <form id="myform">
                <input id="something" type="text">
                </form>

                <button form="myform" type="submit">Submit that form over there</button>


                But I haven't verified this will work.






                share|improve this answer












                I fixed it. It wasn't really clear from the code I posted, but the form had most of the inputs outside the tags. IE, apparently, can't figure out that those tags belong to the form. I fixed it by placing the form tags around all of the input tags. Another solution might be to use the form attribute for input tags:



                <form id="myform">
                <input id="something" type="text">
                </form>

                <button form="myform" type="submit">Submit that form over there</button>


                But I haven't verified this will work.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 at 3:38









                Sam

                5961723




                5961723






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330835%2fdjango-internet-explorer-posts-an-empty-form%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to change which sound is reproduced for terminal bell?

                    Can I use Tabulator js library in my java Spring + Thymeleaf project?

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents