AngularJs Blocks Form Submit without "action"
AngularJs Blocks Form Submit without "action"-In general, AngularJs blocks the form submit, because of empty "Action".
AngularJS (now deprecated) was widely used for building dynamic forms, but developers sometimes encounter issues where form submission fails or causes an unexpected page reload. This typically happens when the form has an empty action attribute. By default, an empty action submits to the current URL, which triggers a full page reload unless the default browser behavior is explicitly prevented. While ng-submit is designed to handle this, some server-side frameworks (like Symfony) generate empty action attributes by default, which can interfere with Angular's event handling in certain browser configurations.
This issue commonly arises when using Symfony with AngularJS. Symfony's form builder generates an empty action attribute by default if none is specified. Without a proper action or explicit event prevention, the browser submits the form to the current URL, causing a full page reload instead of handling it via AngularJS.
To avoid setting a specific URL while preventing the default reload, set the action to a relative path like .. (Note: Avoid using #, as it appends a hash fragment to the URL and causes the page to scroll to the top.)
If you use Symfony Forms, then you have to do like this:
Symfony
<?php
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
$form = $this->createFormBuilder($data)
->setAction('.')
->add('field', TextType::class)
->add('submitButton', SubmitType::class)
->getForm();On the frontend, ensure your HTML form includes action="." and uses AngularJS's ng-submit:
HTML & AngularJS
<form ng-submit="submitForm($event)" action=".">
<input type="text" name="field" />
<button type="submit">Submit</button>
</form>var app = angular.module('myApp', []);
app.controller('MyController', function($scope) {
$scope.submitForm = function($event) {
// ng-submit automatically prevents the default browser submission
// Handle form submission logic here
};
});