Mindjakk 0 Posted January 23, 2015 I understand that is might be something that is already answered and I apologize if it is, I could not find it. What I need to do is build a simple form that has two options, they will be dropdown options. Dropdown A and Dropdown B then a Submit button. This part I understand in HTML, although it may be easier in php or javascript. Then I need it to take the two options and create a "if/then" statement that loads a specific pdf that matches the two options selected. Example. If someone selects Option 1 from Dropdown A and Option 2 From Dropdown B then it loads 12.pdfIf someone selects Option 5 from Dropdown A and Option 3 From Dropdown B then it loads 53.pdfIf someone selects Option 2 from Dropdown A and Option 1 From Dropdown B then it loads 21.pdf and so on... It does not have to be the exact thing just some way to take both inputs and have it equal a specific pdf. Here is the form I built but I don't know what to put in the form_action.php file in order to make it work <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <center> <h1> Get Directions</h1> <form action="form_action.php" method="get" name="directions" target="_new"> <select name="startpoint" size="1"> <option value="north">North Tower Entrance</option> <option value="south">South Tower Entrance</option> <option value="moba">MOB A Entrance</option></select> -----> <select name="endpoint" size="1"> <option value="onco">Oncology</option> <option value="radio">Radiology</option> <option value="pulm">Pulmanary</option></select> <br /><br /> <input type="submit" value="Submit" /> </form> </center> </body> </html> Any help is appreciated, thanks. Quote Share this post Link to post Share on other sites
CroNiX 58 Posted January 23, 2015 Wouldn't the easiest thing to do is to assign the values of the dropdowns to be numeric? Then take the combination of them to create the filename? Quote Share this post Link to post Share on other sites
Mindjakk 0 Posted January 23, 2015 That looks like it might work but what do I put in the form action section of the form? Do I move the javascript into a file or can I put it into the header? Thanks. Quote Share this post Link to post Share on other sites
Mindjakk 0 Posted January 23, 2015 What you did was great, my issue is getting it to actually launch the pdf through the php action script, thanks. Quote Share this post Link to post Share on other sites
CroNiX 58 Posted January 23, 2015 (edited) in form_action.php, you'd do: //grab start/end times, and force them to integers $start = (int)$_GET['startpoint']; $end = (int)$_GET['endpoint']; //build the filename $filepath = '/path/to/file/'; $filename = $start . $end . '.pdf'; //check to see that it actually exists first if (file_exists($filepath . $filename)) { //send file to browser header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($filepath . $filename)); header('Accept-Ranges: bytes'); readfile($filepath . $filename); } Edited January 23, 2015 by CroNiX Quote Share this post Link to post Share on other sites
CroNiX 58 Posted January 23, 2015 The javascript was just showing how to build the filename from the inputs. You don't need it. You didn't describe what you wanted to do beyond just building a filename from the 2 selects. Quote Share this post Link to post Share on other sites
Mindjakk 0 Posted January 23, 2015 Sorry about the additional thread. I have this portion working now. But it still won't let me know load the pdf, It wont' allow the headers to modified in order to load it, thanks. You can see the working script here... http://movidstudios.com/wayfinder/directions.html Thanks again for your help. Quote Share this post Link to post Share on other sites
CroNiX 58 Posted January 23, 2015 Post the code you're using. The html on the website doesn't show us anything. We need to see the PHP you're using. But if you have a "headers already sent" error, it's most likely because you are sending output to the browser before it tries to send the pdf file...perhaps it's the echo'ing you're doing. No output can be sent before the headers. Quote Share this post Link to post Share on other sites
Mindjakk 0 Posted January 23, 2015 (edited) This is the HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <center> <h1> Get Directions</h1> <form action="form_action.php" method="get" name="directions" target="_new"> <select name="startpoint" size="1"> <option value="north">North Tower Entrance</option> <option value="south">South Tower Entrance</option> <option value="moba">MOB A Entrance</option></select> -----> <select name="endpoint" size="1"> <option value="onco">Oncology</option> <option value="radio">Radiology</option> <option value="pulm">Pulmanary</option></select> <br /><br /> <input type="submit" value="Submit" /> </form> </center> </body> </html> This is the PHP <?php $a = $_GET["startpoint"]; $b = $_GET["endpoint"]; //build the filename $filename = $a . $b . '.pdf'; echo "Your Startpoint is:". $a. "<br />"; echo "Your Endpoint is: ". $b. "<br />"; echo $a,$b,".pdf". "<br />"; echo $filename; //check to see that it actually exists first if (file_exists($filename)) { //send file to browser header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($filename)); header('Accept-Ranges: bytes'); readfile($filename); } ?> I'm new to PHP coding so I might have messed it up, thanks. Also I am only echoing to be sure I am getting the proper results, I can remove those, in the end it should just launch a PDF with corresponding file name. THanks. Edited January 23, 2015 by Mindjakk Quote Share this post Link to post Share on other sites
Mindjakk 0 Posted January 23, 2015 YOU WERE RIGHT!! After removing the Echos, I was able to get it to launch the downloader for the pdf I guess my next question is can we launch ti in the browser? Thanks. Quote Share this post Link to post Share on other sites
CroNiX 58 Posted January 23, 2015 Get rid of the echo statements. You can't have those before the header()'s. That's what I meant about "no output before the headers". The way you are coding this also makes it so that the pdf files must be in the same directory as this form_action.php script since you didn't provide a path to the pdf's. Quote Share this post Link to post Share on other sites
CroNiX 58 Posted January 23, 2015 Change header('Content-Disposition: attachment; filename="' . $filename . '"'); to header('Content-Disposition: inline; filename="' . $filename . '"'); Quote Share this post Link to post Share on other sites
Mindjakk 0 Posted January 23, 2015 You are a gentleman and scholar among men. That did it!! Thanks. That is perfect. Quote Share this post Link to post Share on other sites
CroNiX 58 Posted January 23, 2015 Sure thing, glad it's working Quote Share this post Link to post Share on other sites