Run a PHP script with a button

Solved
Hello,

I’m simply looking to add a button on my page that would run a PHP script, let me explain. I have my page.php and I’d like to add a button on it; on click I’d like it to execute MonScript.php. This script creates a PDF (via FPDF). When MonScript.php runs, it should automatically open the file download tab.

I’m on a local hosting (WAMP).

Thank you very much for your response even if it seems basic.

Best regards

1 answer

  1. Moderator
    Hello,

    You can, as needed:
    - use a form that submits to the code that creates your PDF
    - use a link to the PHP script that creates your PDF

    --
    Best regards,
    Jordane
    0
    1. Here's the English translation: Great, I’ve opted for a link to the script, it works but I’d like to improve it a bit more. Basically, MonScript.php generates a PDF for a defined id. I’d like to retrieve the order ID for which MaPage.php is displayed. In MaPage.php it’s just a simple variable, but I’m wondering if it wouldn’t be better to use a form to send this variable with a POST? If that’s the case, could you please show me the steps to follow?
      Thank you very much!
      0
    2. Moderator
      @Heros123Hello,

      You place your button inside a form
       <form method="post" action="MonScript.php" name="monForm"> <input type="hidden" name="id" value="<?php echo $ID_commande;?>" /> <button type="submit">GO</button> </form> 
      0
    3. @jordane45So in my Script.php I just need to change my Orderid which was raw to $orderid? Because after a few tests it still doesn’t work, it shows an error message saying that $orderid doesn’t exist (in Script.php). Should I maybe use the $Get method in my Script.php?
      0
    4. Moderator
      @Heros123To retrieve POST variables
       $orderid = !empty($_POST['id']) ? $_POST['id'] : NULL; 
      0