Skip to content
Advertisement

How to do form submit the PHP way with Angularjs?

I found out that AngularJS sort of blocked the original form’s way of submit and here is another one. Myself, found its troublesome because I need to work with many legacy submit form which use PHP way of submitting form after page refresh to pass $_REQUESTs instead of the JavaScript ajax call like $post or $get.

I know its bad to not submit without refresh. however, to cope with the way how originally the page works, I need to do the submit the “PHP way”, in other words, the form is expected to load the same page with parameter passed back to itself with additional parameter after the page url. (i.e. a page index.php will become index.php?aVar=123, lets assume the submitted the form contain a $_REQUEST[‘aVar’] input value.

Final result as long as somewhat the page got reloaded with the form’s inputs become parameter for the page will be sufficient!

Advertisement

Answer

Ah HA! Here is an easy work around!

so, make sure include those form “input fields” that using angularjs in a ng-app that is NOT applied to the <form> level of the DOM! very important! So now, ng-app can be used WITHIN the form in a “normal PHP way” 😀

Can’t say its working for everyone, but it works for this senario!

Cheers!

For example

<body>
<form>
<div ng-app="ngComponent">
<!-- Do your Angular stuff here -->
</div>
<div> <!-- Do non angular stuff here --> </div>


</form>
</body>
</html>
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement