Jump to content

Displaying Form Submissions from Form Builder


randyj
 Share

Recommended Posts

I've set up the form which displays and takes entries. Now I am trying to get those entries be displayed on a separate page(s). One will be the individual entry itself, the other is a full listing of the entries.

I've done the following:

Enabled Save to ProcessWire Pages from the form settings page

Clicked Send Checked to Pages 

How do I access the form entries that I allowed to be displayed? Under the form settings page, I set the Page Template field to basic-page.

Screenshots are attached to show what I have done so far.

Thanks in advance!

post-1941-0-26023200-1385160669_thumb.pnpost-1941-0-47782000-1385160676_thumb.pn

Link to comment
Share on other sites

randyj,

You might want to create a page as a parent for these entries.

For example:

submissions

-- entry1

-- entry2

-- etc...

Once you have your entries saved to pages, you can access them using the API, just like any other page.

So in the template you use to display entries you could do something like:

$entries = $pages->get("/submissions/")->children();

foreach ($entries as $entry) : ?>

    <p><?=$entry->name_1;?></p>

    <p><?=$entry->description_1;?></p>

<? endforeach; ?>

This is written in the browser, so check it for errors.

  • Like 1
Link to comment
Share on other sites

Hi Reno,

Thank you for your help. I now have the submissions page showing a listing of all the entries. However, when I click on an entry, I get the following error:

Parse Error: syntax error, unexpected T_ENDFOREACH (line 8 of /home/norberts/public_html/index/site/templates/submissions.php) 

This error message was shown because you are logged in as a Superuser. Error has been logged.

 

I used the following code in my submissions.php file:

$entries = $pages->get("/submissions/")->children();

<!-- if ($entries->category == "Mats") echo "Turtle!";?> -->

foreach ($entries as $entry) : ?>
    <p><?=$entry->name_1;?></p>
    <p><?=$entry->description_1;?></p>
<? endforeach; ?>

The commented line is just me testing the value of a checked box, but we can ignore that for now.

I'm a newbie at PHP, so I was a bit confused with the code. Shouldn't there be an opening <? or <?php in front of the foreach loop? I tried that and I just get the following outputted:

$entries = $pages->get("/submissions/")->children();

Also, I'm trying to show more fields on the current Submissions listing page. Currently, the only field being outputted is the Description field. In the screenshots attached, you can see the fields the form uses, and the available fields. 

Thank you for your help!

post-1941-0-15434400-1385396807_thumb.pn

post-1941-0-88340100-1385396925_thumb.pn

Link to comment
Share on other sites

depends on where your opening php tag is, and this is not php comment <!--

use brackets then your editor can show you the matching bracket

<?php
foreach ($entries as $entry) { ?>
    <p><?=$entry->name_1;?></p>
    <p><?=$entry->description_1;?></p>
<? } ?>
Link to comment
Share on other sites

Okay, I've edited submission.php file to this:

$entries = $pages->get("/submissions/")->children();

<?php
foreach ($entries as $entry) { ?>
    <p><?=$entry->name_1;?></p>
    <p><?=$entry->description_1;?></p>
<? } ?>

but on the website, it still outputs the following code:

$entries = $pages->get("/submissions/")->children();
 

Also, sorry for straying further from the original question, but I've been rearranging some of my pages. I would like all entries to show on the submissions page, but have 4 categories in which these form entries can be inside. 

My question is, how would I dynamically set a form entry to fall under /submissions/{sub-category}? I have a form with checkboxes that require a user to choose one of the four sub categories.

Thank you!

post-1941-0-09549800-1385406842_thumb.pn

Link to comment
Share on other sites

<?php
$entries = $pages->get("/submissions/")->children();
foreach ($entries as $entry) { ?>
    <p><?=$entry->name_1;?></p>
    <p><?=$entry->description_1;?></p>
<? } ?>

though in this case i think this is better:

<?php
$entries = $pages->get("/submissions/")->children();
foreach ($entries as $entry) {
    echo "<p>{$entry->name_1}</p>";
    echo "<p>{$entry->description_1}</p>";
    }
?>
  • Like 1
Link to comment
Share on other sites

Thank you for your quick reply.

***EDIT 2*** Okay I got the entries to show in a category, but it's me manually setting the the 'Save to ProcessWire Pages'.

I need to know how I can manually pull in entries based on checkbox field for each of the four subcategories.

Thanks!

post-1941-0-01142300-1385408708_thumb.pn

Link to comment
Share on other sites

Hi Macrura,

Basically, I have a form that has a checkbox with 4 options (which are the 4 categories). When the user submits the form, I would like the entry to fall under the category that is checked.

Right now, I set it up to automatically go into Employment category (screenshot attached). How would I make it so that the checkbox on the form determines which category the entry will fall under?

The development site is located here: http://norbertslist.info/index/

Note: I manually moved the entries out of the Employment category.

post-1941-0-88868400-1385414668_thumb.pnpost-1941-0-69780100-1385414669_thumb.pnpost-1941-0-52323200-1385414670_thumb.pn

Link to comment
Share on other sites

right - ok well i wouldn't use the page tree for categories, i would bucket the pages all under 1 page and then use Url Segments for the categorization; i do this for a lot of reasons, but one being that sometimes clients will want something to be in 2 categories.

to do what you want to do would be pretty easy though, you would need to run a hook before the pages are saved; for that you might check the formbuilder thread there are some examples of code for running hooks with formbuilder.

Link to comment
Share on other sites

You should be able to do categories with form builder in this case. But note that your 'category' field will have to be a field of type 'Page' both in your form and in your ProcessWire fields. I'm guessing that you've currently got 'category' as a regular select field (rather than Page field) in Form Builder?

Link to comment
Share on other sites

You should be able to do categories with form builder in this case. But note that your 'category' field will have to be a field of type 'Page' both in your form and in your ProcessWire fields. I'm guessing that you've currently got 'category' as a regular select field (rather than Page field) in Form Builder?

Hi Ryan,

I'm getting closer I think. I set the field type to 'Page' on both my form and ProcessWire fields. 

I can now see the 'Category ID' in the form entries and limit entries that way.

I still can't figure out how to get the entry to show up under the right 'Category'. Ex: I submitted a form entry called 'Green mat for sale' and put it under the Mats category. On my form entries page, I see that the 'Green mat for sale' entry is under category id #1018, which is correct. But I'm not sure how to have the entry be listed under the correct category.

Thanks!

post-1941-0-75701000-1386005367_thumb.pnpost-1941-0-67431200-1386005368_thumb.pn

post-1941-0-69776700-1386005490_thumb.pn

Link to comment
Share on other sites

I'm assuming your entries have been converted to pages already. Try editing one of those pages and making sure that its category field is consistent with what you expect. If all looks good there, it just comes down to regular PW API selection of the pages that you want. In your case, if you wanted to list the pages in category 'mats' you'd have API code something like this:

$entries = $pages->get("/submissions/")->children("category=1018"); 

Using the ID directly like that "1018" may be efficient, but isn't usually very readable, so you may prefer to use a selector like  "category.name=mats" or "category=/categories/mats/" or whatever suits your particular case. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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