AI websites

Step-by-step tutorial

Why Your AI Website's Cancel Button Submits the Form

Fix a Cancel or Preview button that triggers form validation or submits a form. Identify the button's role, check its HTML type, and retest the real submit button.

Product links on this page are ordinary official links. No affiliate commission is currently attached. Read our disclosure.

Quick answer

If clicking Cancel, Preview, or Show password triggers required-field warnings or submits your form, check that button’s HTML type.

In a normal HTML form, a button without an explicit type can act as a submit button. An action that should only run its own code usually needs type="button". The real Send button should keep type="submit". See the MDN button reference.

You need access to your website editor or original project. Use a preview or test copy before touching a form that sends real messages.

Step 1. Identify which action goes wrong

Open the form and leave a required field empty. Click the problem button once.

  • A field warning appears. The click may be trying to submit the form.
  • The page reloads or sends a request. Record the address and which button you clicked.
  • The button only clears fields. Check whether it is deliberately a reset button.

Next, fill the fields with harmless test details and repeat in a test environment. An empty field may have blocked a submission that would otherwise have gone through.

Keep real customer details out of the test. If the form already sends messages, use its test mode or an isolated copy.

Step 2. Ask AI to inspect the button’s type

In your website project’s AI chat, paste this request. Replace the bracketed details.

On [page URL], clicking [Cancel or Preview] unexpectedly submits the form.
Find this button and check its HTML type and click handler.
It should [describe the intended action] without submitting.
Propose the smallest fix. Keep the real Send button working.
Show the change and test it before publishing.

For a plain HTML form, the intended structure might be:

<button type="button">Preview</button>
<button type="submit">Send enquiry</button>

The Preview button still needs its preview behavior. Setting its type prevents the default submission behavior but does not create a preview or close a dialog.

If an AI-generated button component is used, ask the assistant to inspect the HTML it actually renders. Adding an option to a component helps only if that option reaches the real button.

Step 3. Check whether a script also submits

If the button already renders as type="button", inspect its click handler next.

A script could call the form’s submission method, or a shared handler could run the same action for every button. Ask the assistant to trace that specific click before editing.

Avoid removing all form validation to make the warning disappear. Validation on the real Send action still protects visitors from incomplete submissions.

A reset button also has a different purpose. Use type="reset" only when restoring the form’s fields to their initial values is the action you want. MDN explains the button types.

Step 4. Retest both buttons

After reviewing the change, check:

  1. Problem button, empty form. It performs its intended action without submission warnings.
  2. Problem button, completed form. It performs that action without sending the form.
  3. Send, empty form. Required-field validation still appears.
  4. Send, completed form. A harmless test reaches the intended receiver.

Use the contact-form troubleshooting guide to check delivery. A successful local test does not prove an email arrived.

Publish with the safe update process, then repeat the checks at the real address, including on a phone.

What we checked

In a controlled local browser example, an untyped Preview button triggered validation and then a submission attempt when the required field was filled. Changing it to type="button" kept its preview action and stopped those submission attempts. The separate Send button still triggered validation and, with a completed field, the local submit-event handler.

This was a local example, with no external form service or inbox. Official documentation checked November 13, 2026.