How to trigger PHP code from a button click

Support General How to trigger PHP code from a button clickResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21793
    MartinMartin
    Participant

    Hi,

    I'm able (thanks to some help) to trigger some js actions when a button is clicked on a page.

    Now I need to be able to trigger some functions in PHP from a button click.

    The specific requirement is to have a series of buttons on a form which do things like grabbing data from the database, send it off to external servers and other manipulations which I don't want the users to have any visibility of. They'll just get a simple response saying 'done'. It's all server side action but wants to be triggered from a button on a page.

    I can do this from a standard html button (with a simple <form action="my code.php" etc call) but can't see how to do this from a button in MB.

    Thanks.

    #21800
    Long NguyenLong Nguyen
    Moderator

    Hi,

    To trigger a PHP function when clicking a button or any element, we can use the AJAX. These articles would help you to implement AJAX with PHP.
    https://www.smashingmagazine.com/2011/10/how-to-use-ajax-in-wordpress/
    https://premium.wpmudev.org/blog/using-ajax-with-wordpress/

    #21801
    MartinMartin
    Participant

    Thanks for that. I'll have a read and see where I get.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.