DefaultSubmit plugin
Submit the form if all fields are valid after validating
Usage
The following piece of code is the starting point to use the DefaultSubmit plugin:
<html>
<head>
<link rel="stylesheet" href="/vendors/@form-validation/umd/styles/index.min.css" />
</head>
<body>
<form id="demoForm" method="POST">
...
<button type="submit">Submit</button>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.min.js"></script>
<script src="/vendors/@form-validation/umd/bundle/popular.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function(e) {
FormValidation.formValidation(
document.getElementById('demoForm'),
{
fields: {
...
},
plugins: {
defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
...
},
}
);
});
</script>
</body>
</html>
The sample code above assumes that the FormValidation files are placed inside the vendors
directory. You might need to change the path depending on where you place them on the server.
Instead of submitting the form, you can use an
Ajax request to send the form data to the server.
If you want the form to be validated automatically when pressing its Submit button, use the
SubmitButton pluginUsing the npm packages
If you are using a bundler such as
Webpack,
Rollup,
Parcel or
Vite, etc., to bundle
your application, then it's recommended to use the FormValidation NPM packages.
$ npm install @form-validation/bundle
$ npm install @form-validation/plugin-default-submit
- Import and use the DefaultSubmit plugin:
import { formValidation } from '@form-validation/bundle/popular';
import { DefaultSubmit } from '@form-validation/plugin-default-submit';
formValidation(
document.getElementById('demoForm'),
{
fields: {
...
},
plugins: {
defaultSubmit: new DefaultSubmit(),
...
},
}
);
Changelog