Jump to content

call pdf file when click submit button in a form based on selections


ozalkl

Recommended Posts

how would i able to tell the submit button when clicked to grab the pdf file based on the selections? and how do i grab the selection name?

 

for example:

 

Form name "pdf"

 

selection 1: i choose A

selection 2: i choose B

selection 3: i choose C

 

when hit "submit" button, should call ABC.pdf

 

i would really appreciate if anyone can help me with this part of the code or any tutorials based on the above

<form action="pdfHandle.php" method="post">
<Select name="docName[]">
<option name="a">a
<option name="b">b
<option name="c">c
</select>
<Select name="docName[]">
<option name="a">a
<option name="b">b
<option name="c">c
</select>
<Select name="docName[]">
<option name="a">a
<option name="b">b
<option name="c">c
</select>
</form>

 

pdfHandle.php

<?php
$docName=$_POST["docName"];
$location= implode("",$docName).".pdf";
Header("Location: $location");
exit();
?>

You might want to also just print a link to the pdf to open in a new window instead:

<?php
$docName=$_POST["docName"];
$location= implode("",$docName).".pdf";
echo "<a href=\"$location\" target=\"_blank\">Your pdf is available</a>";
?>

 

 

BUT this is not the way I would do this.  This means you need to have 9 pdf documents always available.  Better would be a single drop down box that reads contents from a MySQL database.  To each their own.

thank you, i will implement using this method, i've already created all possible selections in diff pdf, so i think doing it this way wouldn't make issues since the pdf's are already created with all sort of selection options.

 

is there anything else shall i address to have this method working? additional coding or scripts to run along this method?

It should be complete.  I haven't tested it though, so let me know if there are errors.  I designed it so you can dynamically add fields.  such that if you needed to make it ABCD.pdf all you have to do is copy and paste the select& options.

i tested it, it works great, i altered my selection coding to match the php function, i just have one last question, how do i call the location of the pdf file.

 

i mean currently its abc.pdf what if i want it to be in this folder "pdfs/abc.pdf"

Thanks, glad it works.  All you would have to do is modify the $location variable to what the directory should be:

 

<?php
$docName=$_POST["docName"];
$location= "pdfs/".implode("",$docName).".pdf";
Header("Location: $location");
exit();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.