Jump to content

Recommended Posts

Posted

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.

Posted

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
Posted

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

Posted

Another option could be Ajax-loading those pdf links. You could pass the selected pdf IDs in a url parameter. Of course this requires some frontend (js) work.

Posted

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.

Posted

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.

Posted

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).

Posted

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

Around the receiving Php? I didn't realise I needed one but hadn't done this before. Will try that, thanks.

Posted

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.

Posted

Finally figured this out after finding this post

I needed a trailing slash at the end of my action URL

<form method="post" action="../download-confirmation/" target="_parent">

The form still worked and directed to the correct page so that didn't help.

Posted

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. 

Posted

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?

Posted

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.

Posted

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+"/".

Posted

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?

Posted

@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
Posted

@Peter

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

Or call it like this: 

$input->post("first-name");
  • Like 1
  • Recently Browsing   0 members

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