Federico Posted December 27, 2017 Share Posted December 27, 2017 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 More sharing options...
flydev Posted December 28, 2017 Share Posted December 28, 2017 Hello, replace in your module $page by $this->page and everything should be fine. $form->attr("id+name",'$page->name'); // should be $this->page->name $field = $field->getInputfield($page); // should be this->page 1 Link to comment Share on other sites More sharing options...
dragan Posted December 28, 2017 Share Posted December 28, 2017 @Federico I am just curious - why do you need such a setup? 1 Link to comment Share on other sites More sharing options...
SamC Posted December 28, 2017 Share Posted December 28, 2017 5 hours ago, dragan said: @Federico I am just curious - why do you need such a setup? Same here. Link to comment Share on other sites More sharing options...
Federico Posted December 28, 2017 Author Share Posted December 28, 2017 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 More sharing options...
dragan Posted December 28, 2017 Share Posted December 28, 2017 @Federico I did a little exercise myself after your last forum thread (without using @kongondo's VS though) 1 Link to comment Share on other sites More sharing options...
kongondo Posted December 28, 2017 Share Posted December 28, 2017 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. 2 Link to comment Share on other sites More sharing options...
Federico Posted December 29, 2017 Author Share Posted December 29, 2017 23 hours ago, kongondo said: If you cannot wait until then, I am happy to send you the pre-final Version 005 to use instead. No worries, better wait then Link to comment Share on other sites More sharing options...
Federico Posted December 30, 2017 Author Share Posted December 30, 2017 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 More sharing options...
flydev Posted December 30, 2017 Share Posted December 30, 2017 Hi @Federico try : $editpage = $this->pages->get($pageID); // get the collection of inputs that inside the selected page $inputfields = $editpage->getInputfields(); foreach($inputfields as $inputfield) { $value = $inputfield->value; // do something } Link to comment Share on other sites More sharing options...
Federico Posted December 30, 2017 Author Share Posted December 30, 2017 Hi @flydev thanks. I've got the title of each pre selected values as follow foreach($inputfields as $inputfield ) { $id = $inputfield->value; foreach ($id as $t) { $ti = $t->title; // pulls out all titles } $form->append($inputfield); } Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now