javascript - submit regular form using angular -



javascript - submit regular form using angular -

i have normal html form inputs, action, etc. defined within angular controller. however, form doesn't have submit button. instead has button elsewhere on page outside form, when clicked should trigger normal form submission process. in other words, have external button work normal submit button.

for illustration (with simplified version of have),

<div ng-controller='sendformcontroller"> <form name='my_form' action='/path/to/form_handler.php' method="post"> <input type="text" name="form_data" /> </form> <button ng-click='submitform()">send data</button> </div>

i've been looking solution problem solutions i've been able find (which bit hackish way of thinking) include,

having hidden submit button , trigger press of external button. having code executes $http.post(), etc. when external button pressed. don't want have duplicate action, assembling parameters, etc. in function.

i'm assuming there must way in angular trigger submission of form can't find in docs. can point me in direction of i'm missing?

in sendformcontroller,

$scope.submitform = function() { document.getelementbyid('my_form').submit(); //force submit form after clicking button }

and,

<form name='my_form' id='my_form' action='/path/to/form_handler.php' method="post">

javascript angularjs forms

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -