Jump to content

Display PDF links after form submit


Peter Knight
 Share

Recommended Posts

Hi guys

Probably more a general Dev question so I'm posting it here.

I have a Document Request form form. Apart from basic fields for name, email, phone etc, I also list 10 PDF titles and a checkbox for each.

The form itself is created using an online form service.

I'd like to display a download link on the confirmation page corresponding to each checkbox ticked.

AM I correct in thinking this is the realm of URL parameters and combined with some PW selector?

If it's any help, each PDF is actually a page in PW with a template called "document-detail".

Just looking for broad tips right now while at planning stage.

Link to comment
Share on other sites

If the user can select multiple files for download, you know where they are. You simply can link to the page(s) of them if you have set the new property of mimetype for that template. Then PW will send the apropriate headers for that mime type.

But I would bundle all selected files into one ZIP and present that link for downloading.

  • Like 1
Link to comment
Share on other sites

If the user can select multiple files for download, you know where they are. You simply can link to the page(s) of them 

What I'd like to do is dynamically display them.

IE Although I have a dedicated page listing all available PDFs with links to them, I'd like to display just the PDFs which had checkboxes ticked.

Possibly I can pass a CSS class to the PDFs not selected to hide those on the page etc

Link to comment
Share on other sites

I'm not sure I understand the question. After the form submission, you know which PDF's are checked. Now on the confirmation page, you simply can read the selected page-IDs (corresponding to the PDF pages) from the POST request and display a list with those pages. If you redirect to a confirmation page, you could store the PDF page IDs in the session.

Link to comment
Share on other sites

you simply can read the selected page-IDs (corresponding to the PDF pages) from the POST request 

I get it. Once I have a page ID, I can make a connection between and selected PDF and it's page.

So if I have a form (using FormBuilder) and a PageSelect field outputting an array of checboxes called "select_your_case_studies[]"

<div class="InputfieldContent ">
<div class="InputfieldCheckboxes">
<ul class="InputfieldCheckboxesStacked">
	<li><label><input type="checkbox" name="select_you_case_studies[]" id="Inputfield_select_you_case_studies_1412" value="1412"><span class="pw-no-select">Condé Nast</span></label></li>
	<li><label><input type="checkbox" name="select_you_case_studies[]" id="Inputfield_select_you_case_studies_1413" value="1413"><span class="pw-no-select">Charles Stanley</span></label></li>
	<li><label><input type="checkbox" name="select_you_case_studies[]" id="Inputfield_select_you_case_studies_1414" value="1414"><span class="pw-no-select">Global Logistics Firm</span></label></li>
</ul><input type="hidden" class="findPagesSelector" data-label="title" value="template=a-document, Document_Type=Case Study">
</div></div>

Would I use the following to echo the selected check boxes?

$value = $input->post['select_your_case_studies'];

I'm unsure as to why nothing is outputting on my confirmation page.

Link to comment
Share on other sites

Do you have a "form" tag around this snippet? (I guess so, just to make sure)

Check whether you have a redirect before you try to access these post values (Inspector -> Network tab).

Link to comment
Share on other sites

Yep it's a form created by Form Builder (the PW module).

Starts with

<form id="FormBuilder_document-download" class=" FormBuilderFrameworkFoundation InputfieldFormWidths InputfieldFormNoHeights InputfieldForm" name="document-download" method="post" action="./" data-colspacing="0">

Ends with a closing form tag too.

Link to comment
Share on other sites

Then you surely had a redirect beforehands (from "download-confirmation" to "download-confirmation/"). That's why I suggested to check the Network tab for any redirects - post variables are lost if there's any. 

Link to comment
Share on other sites

Then you surely had a redirect beforehands (from "download-confirmation" to "download-confirmation/"). That's why I suggested to check the Network tab for any redirects - post variables are lost if there's any. 

I hadn't manually set any. Would it be a manual redirect specified somewhere in the admin or a module or more likely a NGINX directive?

Link to comment
Share on other sites

Regarding pulling post variables on the confirmation page, why would this work

<?php
if(!empty($_POST['Case_Study'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['Case_Study'] as $selected){
echo $selected."<a href='#'>{$selected->title}</a></br>";
}
}
?>

and the more "traditional" PW syntax doesn't

<?php
if(!empty($_POST['Case_Study'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['Case_Study'] as $selected){
echo"<a href='{$selected->url}'>{$selected->title}</a></br>";
}
}
?>

The first example is from a PHP tutorial where I simply update variable names. The second is what  thought would be more correct and in line with what I had been using for more regular selector echoes.

Link to comment
Share on other sites

I hadn't manually set any. Would it be a manual redirect specified somewhere in the admin or a module or more likely a NGINX directive?

Probably the server, redirects urls without trailing slash to url+"/".

Link to comment
Share on other sites

I have errors turned on. It basically outputs nothing. 

This works and confirms that my field 'first-name' exists and is posting

<?php echo $_POST['first-name']; ?>

It outputs Peter

Looking at the input docs, the following PW API call will confirm wether the field exists and has data 

<?php
if($input->post->first-name === null) echo "First name doesn't exist";
else if(!$input->post->first-name) echo "First name exists, but is blank";
?>

This returns

First name exists, but is blank even though it returns a value in the first code example

Is there something I'm missing regarding the PW API of

$value = $input->post->first-name;

and how to use it?

Link to comment
Share on other sites

@Peter

Rename your field to "first_name". PHP does not support variables with dashes.

else if(!$input->post->first-name) echo "First name exists, but is blank";

From the code above you can't say if it's empty or does exist, because NULL or EMPTY are casted implicitly to false by PHP. You'd need the following distinction:

if ($input->post->first_name === null) {
  echo 'First name does not exist';
else if ($input->post->first_name === '') {
  echo 'First name exists but it\'s empty';
}
  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...