Skip to content

Instantly share code, notes, and snippets.

@jarrettbarnett
Last active January 31, 2017 22:44
Show Gist options
  • Save jarrettbarnett/1a682e489e486e92f676b16a4d3a9607 to your computer and use it in GitHub Desktop.
Save jarrettbarnett/1a682e489e486e92f676b16a4d3a9607 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Report Builder</title>
</head>
<body>
<section class="report-section">
<div class="text-block">
<h1>Report Builder</h1>
</div>
{exp:jb_attachpdf:get_entries entries="{segment_3}" prefix="jb" parse="inward"}
{exp:channel:entries limit="20" entry_id="{jb:entries}"}
<h1>{title}</h1>
{page_content}
{city_intro_content}
{city_sidebar_content}
{city_main_content}
{/exp:channel:entries}
{/exp:jb_attachpdf:get_entries}
</section>
</body>
</html>
<section>
{exp:freeform:form
form_name="contact"
return="site/report_builder"
notify_user="yes"
user_email_field="email"
}
<dl>
{freeform:all_form_fields}
{if freeform:field_type != 'hidden'}
<dt><label>{freeform:field_label}</label></dt>
<dd>{freeform:field_output}</dd>
{/if}
{/freeform:all_form_fields}
<input type="hidden" name="pdf_press_entries" value="{exp:cookie_fav:favourites}{if has_favourites}{favourites_entry_ids}{/if}{/exp:cookie_fav:favourites}"/>
<input type="hidden" name="pdf_press_template" value="site/email_pdf_report" />
<input type="hidden" name="pdf_press_upload_fieldname" value="report" />
<input type="hidden" name="pdf_press_filename_fieldname" value="report_filename" />
</dl>
{if freeform:captcha}
<p>Please enter the word you see in the image below:</p>
<p>
{freeform:captcha}
<input type="text" name="captcha" />
</p>
{/if}
<p>{freeform:submit}</p>
{if freeform:no_results}
<p>
Specified form was not found. Please make sure you have specified the
correct short name of the form in the <b>form_name</b> parameter.
</p>
{/if}
{/exp:freeform:form}
</section>
{!-- this tag takes a hyphen separated list of entry IDS and converts them to be pipe delimited --}
{exp:jb_attachpdf:get_entries entries="{segment_3}" prefix="jb" parse="inward"}
{jb:entries}
{/exp:jb_attachpdf:get_entries}
{!--
parameters:
entries (required): hyphenated list of entries, e.g. 5-13-17 (for entries 5, 13, and 17)
prefix (optional): the prefix to use (defaults to "jb" when not provided . Note that the colon is added automatically)
--}
@jarrettbarnett
Copy link
Author

jarrettbarnett commented Jan 26, 2017

The following "hidden fields" will need to be created in FreeForm and associated with the "Form" of choice.
Also notice how we're intentionally excluding hidden fields on freeform_pdf_press.html line 10.

  • pdf_press_entries - the entry_ids to include in the report
  • pdf_press_template - the template for PDF Press to call
  • pdf_press_upload_fieldname - the Freeform fieldname for the file_upload field (we associate the PDF Press file to the field)
  • pdf_press_filename_fieldname - we store a string of the filename in this field

A "file_upload" field needs to be created in Freeform as well which will be used to store and reference the PDF that is generated. You can name this field anything you like, e.g. "report". Once you've created this field, you just need to specify that name in the "pdf_press_upload_fieldname" hidden form field.

Note that whatever fieldname that you specify for: <input type="hidden" name="pdf_press_upload_fieldname" value="" />
...that it will be used to determine where the PDF files will be stored.

I suggest that you create a new file upload location specific for these PDFs. I also suggest creating a cron to wipe out old reports. The following formula is used to create reports:

custom-report-date(YmdHis)-(randomnumbers).pdf

A cron could therefore be written to remove all PDFs older than 30 days by utilizing PHP date() methods and wildcard operators like "*": e.g. $ rm custom-report-20161226* . which would remove all PDFs generated on 2016-12-26

Future improvements can be made to the add-on where-as the generated PDFs are not stored on the server; however, it may come in handy being able to view the generated PDFs via the Freeform backend.

@jarrettbarnett
Copy link
Author

Note that you'll probably want to create a new form (instead of Contact Us) and leave out the typical fields (First Name, Last Name, etc.) in lieu of just an Email field (to receive the emailed report).

I would also suggest creating a new "user notification" template that you can use to improve the user notification email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment