• Resolved cheeco83

    (@cheeco83)


    Hello,

    your PHP snippet tool works generally very well for me, but there is one problem that I cannot resolve. I want to place a “Download” button on my page. By clicking it, a PHP script should be excecuted that creates the download Content. Usually, one would do it like this:

    <form action="download.php">
        <input type="submit" value="Download">
    </form>

    When I try this with PHP Code snippets and I replace the download.php with the shortcode, i.e.

    `<form action=[wbcr_php_snippet id=”9″]>’

    it does not work. Can you enlighten me how to run a snippet while clicking on a button?

    Thanks,

    Stefan

Viewing 1 replies (of 1 total)
  • Plugin Author webcraftic

    (@webcraftic)

    Hi,

    Create a snippet to run everywhere with this code:

    function wbcr_cheeco_download_action()
    {
      if( isset($_GET['wbcr_cheeco_download_action']) ) {
        // Insert here your php code, which must be executed
        echo 'Download file'; // remove str
        exit; // remove str
      }
    }
    
    add_action('init', 'wbcr_cheeco_download_action');

    Paste such a link into the form by changing the domain of the site to your
    http://yoursite.com/?wbcr_cheeco_download_action
    Example:

    <form action="http://yoursite.com/?wbcr_cheeco_download_action">
        <input type="submit" value="Download">
    </form>

    Best regards, Alex

Viewing 1 replies (of 1 total)

The topic ‘Execute snippet on button click’ is closed to new replies.