Temepest74 Posted November 19, 2020 Share Posted November 19, 2020 I got assigned the task of making a button inside a form. I am trying to make a button inside a helper form which will not reload my page. Any tisp? Link to comment Share on other sites More sharing options...
MikeCodes Posted November 20, 2020 Share Posted November 20, 2020 Good question, i have the same question... hope someone can answer it Link to comment Share on other sites More sharing options...
Guest Posted November 20, 2020 Share Posted November 20, 2020 I'd love to help, but I don't understand. Do you need two buttons in the form? Something like the Save button and the Save and stay button? Please screen what you need. Link to comment Share on other sites More sharing options...
Temepest74 Posted November 20, 2020 Author Share Posted November 20, 2020 I need 2 buttons: 1) Send message 2) Check the price I found a way around it but I still look for a way to not reload the page $back = $_SERVER['HTTP_REFERER']; if (!empty($back)) { //check for price with server Tools::redirectAdmin($back . '&price_checked=1'); } Link to comment Share on other sites More sharing options...
ClassyDevs Posted November 25, 2020 Share Posted November 25, 2020 Hi There, There is a plenty of way to integrate ajax functionality to an admin module controller. First you need to bind an ajax function on click of that button. You also need to send the module admin controller link to the js file. You can send the file via custom script tag in your helper form. <?php $link = new Link(); $urladmin = $link->getAdminLink( 'YourControllerName' ); ?> <script type="text/javascript"> var priceExpiryDate = "{$urladmin}"; </script> Then you can use ajax to fire function on the server. $.ajax({ type: 'POST', cache: false, dataType: 'json', url: adminajax_link, data: { ajax: true, action: 'yourActionName'//lowercase with action name }, success : function (data) { console.log(data); }, error : function (data){ console.log(data); } }); Then do your php on code on the function e.g. that is your actionname in your admin controller class. public function ajaxProcessYourActionName() { echo json_encode('foo');//something you want to return exit; } Please mind the camel case of the name. Boom It is done. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now