How can one submit a form without using submit button

How can one submit a form without using submit button

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Intercepting Form Submission via JavaScript

Submitting a form without a visible submit button is a common pattern in modern web applications, often used to streamline user workflows or handle data submission through API calls rather than traditional server-side redirects. The core mechanism relies on intercepting the default form submission behavior and replacing it with custom logic.

When an HTML form is submitted, the browser triggers a submit event on the <form> element. By default, this event causes the browser to gather the input values, encode them as a URL query string or multipart data, and send an HTTP request to the action URL defined in the form tag. To prevent this automatic behavior, you must attach an event listener to the form element that prevents the default action.

Preventing Default Behavior

The most straightforward approach involves using the submit event listener combined with event.preventDefault(). This method stops the browser from reloading the page or sending the data immediately, allowing your JavaScript code to take control of the request lifecycle.

Consider a basic setup where a form targets a PHP endpoint but you want to handle the submission via AJAX instead:

<form id="myForm" action="/submit-data" method="POST">
    <input type="text" name="username" required>
    <input type="email" name="email" required>
    <!-- No submit button present -->
</form>

On the client side, you initialize an event listener:

document.getElementById('myForm').addEventListener('submit', function(event) {
    // Prevent the browser from performing a standard form submission
    event.preventDefault();

    // Collect form data
    const formData = new FormData(this);

    // Send data using fetch API
    fetch('/submit-data', {
        method: 'POST',
        body: formData,
        headers: {
            'Accept': 'application/json'
        }
    })
    .then(response => response.json())
    .then(data => {
        // Handle success
        console.log('Form submitted successfully:', data);
    })
    .catch(error => {
        // Handle errors
        console.error('Submission failed:', error);
    });
});

By calling event.preventDefault(), the browser does not navigate to /submit-data. Instead, the fetch API sends the request asynchronously. This keeps the user on the current page, allowing you to display loading states or success messages dynamically without a full page reload.

Leveraging Laravel for Backend Handling

If you are building with PHP and utilizing the Laravel framework, the backend logic remains largely unchanged regardless of how the form is submitted. Laravel's request() helper function captures the incoming data whether it arrives via a standard POST request or an AJAX call. You can access the input fields using $request->input('username') or $request->only(['username', 'email']).

However, when handling submissions without a submit button, you must ensure that your backend validation and response strategies align with asynchronous behavior. In Laravel, returning a JSON response from a route handler is standard for AJAX requests:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

public function store(Request $request)
{
    $validator = Validator::make($request->all(), [
        'username' => 'required|string|max:255',
        'email' => 'required|email|unique:users,email',
    ]);

    if ($validator->fails()) {
        return response()->json($validator->errors(), 422);
    }

    // Proceed with business logic...
    // $user = User::create($request->all());

    return response()->json(['message' => 'User created successfully'], 201);
}

This approach ensures that if validation fails, the frontend receives a structured error object rather than an HTML error page or a redirect, which would break the single-page application experience.

Trade-offs and Accessibility Considerations

While removing the submit button simplifies the UI, it introduces specific accessibility and user experience challenges. Screen reader users and keyboard navigators often rely on visible controls to understand form submission points. If no explicit trigger exists, assistive technologies may not announce when a form is ready to be submitted or how to initiate the action.

To mitigate this, you should provide a programmatic way to submit the form for accessibility purposes. One common pattern is hiding an invisible submit button that triggers the same JavaScript event:

<input type="submit" style="position: absolute; left: -9999px;" id="hiddenSubmit">

Then, in your JavaScript, you can listen to clicks on other interactive elements (like a "Save" link or icon) and programmatically dispatch the submit event:

document.getElementById('save-icon').addEventListener('click', function() {
    // Dispatch a custom event if needed, or directly trigger form submission
    const event = new Event('submit', { bubbles: true });
    document.getElementById('myForm').dispatchEvent(event);
});

Alternatively, you can use the native HTMLFormElement method to programmatically submit after validation passes:

this.checkValidity(); // Native HTML5 validation
if (this.checkValidity()) {
    this.submit();
}

Conclusion on Implementation Strategy

Submitting a form without a physical button requires careful attention to event handling, asynchronous response management, and accessibility compliance. The combination of event.preventDefault(), the Fetch API, and proper Laravel route responses provides a robust foundation for modern web applications. Always ensure that validation feedback is returned in a format the client can parse, and consider providing hidden or programmatic triggers to maintain compatibility with assistive technologies.

Our network