Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
How to call 2 Functions at the same time using Twig AJAX Form?

I'm using OctoberCMS based on Laravel and Twig.

I'm using a Twig AJAX Form that has 2 buttons. Each call a PHP function, actionOne() and actionTwo().

How do I make the second button call both functions at the same time?

Using multiple data-request on a button doesn't work. And using multiple functions separated by comma in data-request also doesn't work.

Form

{{ form_open() }}

    <button type="button" data-request="actionOne">Action 1</button>
    <button type="button" data-request="actionTwo">Action 1 & 2</button>

    <input type="checkbox" name="queuedOne[]" value="{{ record.one }}" />
    <input type="checkbox" name="queuedTwo[]" value="{{ record.two }}" />

{{ form_close() }}  

Edit: I have corrected the values of data-request and name.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

There are a couple of different ways you could accomplish this.

First option, you could create a third PHP method that simply does both of the things that you want to accomplish and then call that instead:

function onActionThree() {
    onActionOne();
    onActionTwo();
}

and

<button data-request="actionThree">Click me for both previous actions</button>

Second option, you could utilize the AJAX Framework JS API to make two separate AJAX requests to actionOne and actionTwo.

<button id="action-three-btn">Click me for both previous actions</button>

<script>
   jQuery(document).ready(function ($) {
       $('#action-three-btn').on('click', function (e) {
           e.preventDefault();
           $(this).request('actionOne');
           $(this).request('actionTwo');
       });
   });
</script>

I'll leave this off with a final comment, please read https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem and http://xyproblem.info/. This vague abstraction of your questions isn't helping anyone actually address your real problem.

over 4 years ago · Santiago Trujillo Report

0

I didn't know this CMS but If you can write own js code. Then use this

$('document').ready(function(){

    function onOne(){

        here your function

    };

    function actionTwo(){

        here your function

    };


    $("#BUTTONNAME").on('click mouseenter keyup keypress',function(){

        onOne();
        actionTwo();

    });

});

Also I give u an advice, all this CMS stuff out there make the Programming not easier. Wrote your own Stuff an then you dont have this problems.

Hope it help

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!