Jump to content

How to populate a custom module with fields from template


Federico
 Share

Recommended Posts

Dear Community,

I would like to create a module in the admin, that echoes all fields existing in a template (like to mimic a page with same template) . So far so simple, but this gives me an error..

...

public function ___execute(){

    // Build form
    $form = $this->modules->get("InputfieldForm");
    $form->action = "./";
    $form->method = "post";
    $form->attr("id+name",'$page->name');

    // Build fieldset
    $fieldset = $this->modules->get('InputfieldFieldset');
    $fieldset->label = 'Personal Data';

    // Read out template fields and append them to the fieldset
    $taxonomy = $this->templates->get("taxonomy");
    foreach ($taxonomy->fields as $field)
    {
    	$field = $field->getInputfield($page);  // THIS GIVES ERROR
    	$fieldset->append($field);  // THEREFORE ALSO THIS GIVES ERROR
    }

    $form->append($fieldset);

    // Submit
    $submit = $this->modules->get("InputfieldSubmit");
    $submit->attr("value","Anmelden");
    $submit->attr("id+name","submit");
    $form->append($submit);

    return $form->render();
}

Something wrong inside the foreach....

Link to comment
Share on other sites

thank you @flydev, now I understand that under classes I've always to add $this as a reference to the current class

@dragan, @SamC, this is just an exercise for me to create a module that echoes fields from an existing template, just to better understand the pw api.... :)

 

My goal is instead to create an admin module that uses the great @kongondo visual selector fieldtype option, than generate a pdf with the selected values.

..But, I cannot really use the visual page selector in module istance, as the modal window appears but the action button is not shown (like "add pages" to list)

is only me having this?

thanks!!

 

Link to comment
Share on other sites

2 hours ago, Federico said:

But, I cannot really use the visual page selector in module istance, as the modal window appears but the action button is not shown (like "add pages" to list)

is only me having this?

@Federico,

There were a number of issues in Version 004 of VPS (the one you got) when used in ProcessWire 3, especially if using the default theme. All those issues have been ironed out in Version 005. It is currently being beta tested. I hope to release it next week. If you cannot wait until then, I am happy to send you the pre-final Version 005 to use instead.

  • Like 2
Link to comment
Share on other sites

Hi @flydev

I know this is no brainer question, sorry for bothering. Any help on how can this form input from a page:

$editpage = $this->pages->get($pageID);

// get the collection of inputs that inside the selected page
$inputfields = $editpage->getInputfields();

could retrieve also values (if any) pre-populated in that page (from the PW page tree, not from the module). Like so it will retrieve only the inpufields, without prepopulated values

So eventually you have in custom module the same information of what you have on targeted page, with the sole purpose of doing some logic in custom module

thank you very much!

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