parsley form not submitting when submit button has

2019-08-01 07:24发布

问题:

I just discovered that my form isn't submitting when i give the submit element the name="submit" attribute. When I change the the name to something else, it works perfectly!

I am using parsley.remote.min.js * Version 2.0.3 - built Mon Jul 21 2014 11:58:33

Sorry I cannot provide code right now, I just wanted to throw that out there. Is it possibly I am doing something wrong?

回答1:

When you name a form element "submit", you inadvertently override the form's submit method with an input object. For example, with this:

<form id="testForm">
    <input type="text" name="testInput" />
</form>

You can now access the input element by name through a property on the form object:

var testInput = document.getElementById('testForm').testInput;

Forms have a submit() method you can call programmatically (which is the same one invoked by clicking a button or input of "submit" type):

document.getElementById('testForm').submit();

Perhaps now you can see the problem by naming a form element "submit" -- you're taking away the form's ability to be submitted because submit() no longer exists -- it's been redefined as a property that returns a reference to your submit button.

More explanation is available here:

  • Why Form Elements should not be named submit?