Jump to content

Populate form submissions into repeater field on admin page (a different approach)


Stefanowitsch
 Share

Recommended Posts

First: This is a mix of an API, Module Development and General Support question here.

I want to populate a field on an admin page with form submissions.

Yeeeees I know this has been asked a few times before but I did not find a solution to my approach here: I don't want to add a template-XY in the backend and create pages underneath that template for each submission.

What I would like to do is the following:

Have a link inside the setup dropdown that goes to a single page. This page has a repeater field that holds formatted HTML mail message bodies for each submit.

That's it.

I have little to no experience in module development or backend development. I know how to populate fields via API but I need answers to a few fundamental questions here.

1. Creating the Dropdown Link

I used @bernhard's tutorial for custom admin pages to create a simple module and thus a new entry (and a corresponding template) for the form submissions. That works fine! The page underneath is completely blank at the moment.

image.png.8ab7c2cc731087e439a6d192ef6c8f1d.png

2. Adding the Repeater Field

Do fields need to be added to a certain page to be populated or can they act "stand-alone"?

I created a repeater field which holds body fields for the mail messages. This field is attached to no template. I wan't this field to be populated and displayed on the new admin page.

Do i need to add this field to the new admin page to populate it? And how is this achieved? I can't edit the template and add fields since this page uses the "admin" template (otherwise it won't appear in the dropdown).

I can "get" my repeater field and dump it in the console from the module code like this. Is this a usual method?

<?php namespace ProcessWire;
class ProcessFormSubmissions extends Process {
    public function ___execute() {

        $repeater = $this->fields->get('rep_form_submissions');

        bd($repeater);

        foreach ($repeater as $item) {
            echo $item->body;
        }

    }
}

3. Populating the Repeater Field 

In my custom form logic I would like to do something like this:

$submits = $fields->get('rep_form_submissions')->getNew();
$submits->body = $message;
$submits->save();

But this results in an exception:

Exception: Method RepeaterField::getNew does not exist or is not callable in this context

Why can I dump the repeater field inside the console but can't add content the same way?

What do you think about my approach? I'm interested in hearing your opinions or getting some advices here 🙂

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