Problem creating PDF of search results

9 posts by 2 authors in: Forums > CMS Builder
Last Post: November 25, 2019   (RSS)

Hi All,

Having a bit of a brain malfunction using createPDF v 1.09.

I’m trying to create a pdf of the results of a search form submission (on the same page), and can’t seem to get the code to work correctly.

At the top of my page I have:

<?php if (@$_REQUEST['pdf']) { createPDF_fromOutput('inline', 'popup.pdf'); } ?>

And just before the foreach loop that displays the search results I have:

<?php if (@$_REQUEST['save'] == 1):?> <a class="alt_navigation_font" href="?pdf=1">CLICK TO CONVERT THIS PAGE TO A PDF</a><?php endif ?>

A PDF is created, but only shows the search form and not the results of the search.

Any suggestions?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - November 16, 2019 - edited: November 16, 2019

Hi Daniel,

I've managed to get createPDF working again and have posted what I found to be the issues on the other thread https://www.interactivetools.com/forum/forum-posts.php?82122 .

I'm still somewhat lost regarding this issue of generating a PDF of search results and have attached the search form viewer code.

BTW, when I comment out the line you suggested, I get the same result in the browser as if the form was not submitted.

I'm hoping that you can offer a few concrete code suggestions based on the attached viewer.

If this proves to be more complex then can be handled on the forum, I'd be happy to use one of your paid options for a solution.

You can see the on line results of the existing code at http://jkwebdesigns.com/eg/pdftest.php

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

pdftest.php 32K

By daniel - November 18, 2019

Hi Jerry,

I had misinterpreted a bit of your original post (I thought this was saving a record, rather than a search page) and had only provided you with half of the solution. Because you want to create a PDF of the search results, you need to simulate the form being submitted at the same time as the PDF generation. Clicking the link with "?pdf=1" clears all of the search values, as well as the "save" value that tells the page to show the search results.

One fairly minimal solution I can think of is instead of using a "convert this page to PDF" link, you could add a checkbox to the form with the name "pdf" and value "1" labelled something like "View search results as a PDF" so that the user can choose to receive a PDF of the results when they submit the form rather than clicking a link afterwards.

Another simple - but more tedious - solution is essentially #2 from my previous post, except you need to add "save=1" to the URL in addition to the relevant form values. A simple working example is http://jkwebdesigns.com/eg/pdftest.php?pdf=1&save=1&genre_keyword[]=1. The two main tasks you'd have are 1) building the URL string based on the submitted form values, and 2) updating the code to account for when both $_REQUEST['pdf'] and $_REQUEST['save'] are on; e.g. removing the "convert this page to PDF" link.

Let me know if you have any questions about the above, or, if you think you'll need some direct help, feel free to send us an estimate request: https://www.interactivetools.com/estimate/

Thanks!

Daniel
Technical Lead
interactivetools.com

Hey Daniel,

Thanks for this. I'll give both a try and see where that gets me.

You're the BEST!

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Daniel,

Again a well earned vote of THANKS!

I implemented the first idea and it works perfectly for my needs.

Appreciate you folks having our backs, all the time.

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - November 23, 2019 - edited: November 23, 2019

Hi Daniel,

I finally think I’ve figured out the intermittent problem I'm having with createPDF and the ‘content not found’ error.

The page I’m trying to convert to a PDF is index.php.

If I request a PDF with the URL as http://www.my_site.com/eg/ the request ends up as http://www.my_site.com/eg/? which throws the ‘content not found’ error.

If I specifically use the URL http://www.my_site.com/eg/index.php and then request the PDF, createPDF works every time.

I could create a new page with a different file name, but I’m betting that there’s a more elegant approach.

Any ideas?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By daniel - November 25, 2019

Hi Jerry,

Most often the "?" in the URL bar is due to a form set up like this:

<form action="?" method="post">

You should be able to correct your issue by changing the "?" to "index.php" like this:

<form action="index.php" method="post">

The only real drawback here is if you ever change the filename or want to copy the form to another page you'll need to update it, whereas the "?" is more portable.

Let me know if that helps!

Thanks,

Daniel
Technical Lead
interactivetools.com

Thanks, Daniel, 

I was going to try that, but is seemed too simple...

Guess I should have given it a go before reaching out.

Thanks again,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php