Does SubmitField need a validator?

python, wtforms

Solution

I think you do. Looking at the source code there is nothing that would make a `SubmitField` required.

The `SubmitField` is really just a `BooleanField`:

class SubmitField(BooleanField):
    """
    Represents an ``<input type="submit">``.  This allows checking if a given
    submit button has been pressed.
    """
    widget = widgets.SubmitInput()

The associated widget is just an Input widget that has type="submit". It also seems to use the label of the SubmitField as the text in in the HTML.

class SubmitInput(Input):
    """
    Renders a submit button.

    The field's label is used as the text of the submit button instead of the
    data on the field.
    """
    input_type = 'submit'

    def __call__(self, field, **kwargs): 
        kwargs.setdefault('value', field.label.text)
        return super(SubmitInput, self).__call__(field, **kwargs)

It doesn't seem to do much more than this.

Problem

I am new to WTForms. I've got a user registration form with a submit button: ``` submit = SubmitField('Submit') ``` I want to ensure the form is submitted via pressing the submit button and not some other way. In the docs it states that ``` class wtforms.fields.SubmitField(default field arguments) Represents an <input type="submit">. This allows checking if a given submit button has been pressed. ``` Which raises a question: For my case, do I need to add a "Required" validator? e.g., does it need to be: ``` submit = SubmitField('Submit', [validators.Required()]) ```

Original source