Can I trigger a form submit from a controller?

You can add submit method to a FormController. I did so:

<form ng-form-commit action="https://stackoverflow.com/" name="payForm" method="post" target="_top">
    <input type="hidden" name="currency_code" value="USD">
    <button type="button" ng-click='save(payForm)'>buy</button>
</form>

.directive("ngFormCommit", [function(){
    return {
        require:"form",
        link: function($scope, $el, $attr, $form) {
            $form.commit = function() {
                $el[0].submit();
            };
        }
    };
}])

.controller("AwesomeCtrl", ["$scope", function($scope){
   $scope.save = function($form) {
     if ($form.$valid) {
         $form.commit();
     }
   };
}])

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)