Federico
Members-
Posts
106 -
Joined
-
Last visited
Everything posted by Federico
-
Hi @dragan looks good, I will play with it and see what I can do As of the prepend/append custom php files to the foreach pdf generation, nevermind - I've just found a way which is working just fine: $pdf->markupMain = ''; $pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/_coverFront.php'); //front page foreach($pageArray as $item) { $pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/default.php', ["page" => $item]); //actual book content } $pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/_coverBack.php'); // back page
-
Great module, I am using it extensively Couple of questions: - Do you know how to merge or prepend a multipage pdf file to the dynamically generated one? header and footers are repeated for all pages, whereas I am looking for something like a table of content - Is there any possibility to update the mpdf to the 7th version from the current 5.6? thanks a lot!
-
Hi there, how to get the name of the clicked button after form submission, a form that contains a repeater inputfield. This is the tracy results after form submission, where I have to get the following: - how to get the name of the button clicked to submit the form (green selected slot)? - convert this $this->input->post->button_form_repeater_item_2398 into something like $this->input->post->$repeaterName, where $repeaterName should be the repeater name to get fields from (multiple repeaters with multiple submit button with unique ids) - taken from the button name all the above is possible via javascript, with a simple (jquery) var buttonClickedID = this.id; my implementation looks like this now: public function init() { if($this->input->post->button_form_repeater_item_2398) { $this->exportBrochure2pdf(); } } public function exportBrochure2pdf($event) { foreach($this->input->post->book_selector_repeater2398 as $key => $value){ // book_selector_repeater2398 should be a variable instead, reflecting the clicked button name corresponding to the related repeater name $p = $this->pages->get($value); echo htmlentities("ID: $p->id" . " - Title: $p->title") . "<br />"; $pageArray[] = $this->pages->get($value); } } I can't find any proper solution for this Thank you in advance
-
foreach iteration to create nested fieldset items
Federico replied to Federico's topic in Module/Plugin Development
I do not know why I didn't think about that, in fact regardless the number of submit buttons (equal to the number of grandchildren in my case), the form is only one and therefore the submitted data will be always the same (involving all inputfields from all grandchildren pages). [thanks Robin] Dealing with this, my scenario is to see whether the form (submit_form_report) is submitted from the init() if($this->input->post->submit_form_reports) { $this->executeFormInputsProcessing(); } If yes, then I have to check every single inputfield to sanitize and whitelist them, like this protected function executeFormInputsProcessing() { foreach($this->input->post->submit_form_reports as $key => $value){ if(empty($value)) continue; // discard empty values // processing inputfields as a single item - is it the most appropriate way doing this one by one...? if ($key == '1061_reports_manager') { // page array $p = $this->pages->get($value); $pname = $p->name; // grab the page and its name $var_array = array(); foreach ($value as $a) { $var = $this->sanitizer->pageName($a); // sanitize all values (page reference array) $var_array[] = $var; } $this->input->whitelist('something', $var_array); //$input->whitelist('expertise', implode(',', $var_array)); } } } not sure though if I have to duplicate every conditional if($key == 'somethingAgainstToCheck') for each inputfield, as I have like 50 inputfields overall and it will not really handy when scaling -
foreach iteration to create nested fieldset items
Federico replied to Federico's topic in Module/Plugin Development
I've also implemented pretty much the same conf to make each inputfields name unique, many thanks for this hint. Fortunately, In may case I have submit buttons for each grandchildren inputfields wrappers, so once a user submit the form by clicking one grandchildren form button, only the related form vars will be taken into account with this standard conditional if($this->input->post->submit_1061) // only inputfields for the grandchildren form with ID 1061 therefore there shouldn't be any issue related to overwriting fields I guess. However, the major issue I am facing is that I cannot retrieve vars from the post submission -
foreach iteration to create nested fieldset items
Federico replied to Federico's topic in Module/Plugin Development
@Robin S maybe (for sure) you know why I can't get input vars from the above form, this code is located in module init() if($this->input->post->submit) { echo "There are " . count($this->input->post->submit) . " post variables <br /> <hr>"; foreach($this->input->post->submit as $key => $value) echo htmlentities("$key = $value") . "<br />"; } I see the submit button actually submitting the form, but no vars are rendered from the above code, it just says there are 1 post variables regardless the real number of values submitted for several inputfields + Tracydebbuger says that the $value is an invalid argument Invalid argument supplied for foreach() Thank you very much -
foreach iteration to create nested fieldset items
Federico replied to Federico's topic in Module/Plugin Development
Thanks Robin, works properly - my code was too dirty with redundant parts while yours look pretty neat. I had to change it a little in order to ignore some specific fields, such as title: $form = $this->modules->InputfieldForm; $page_01_reports = $this->pages->get(1038); $ignorefields = array("title"); foreach($page_01_reports->children as $child) { if(!$child->hasChildren) continue; $fs_level_1 = $this->modules->InputfieldFieldset; $fs_level_1->label = $child->title; $fs_level_1->collapsed = Inputfield::collapsedNever; foreach($child->children as $grandchild) { $inputfields = $grandchild->getInputfields(); // new fieldswrapper needed to get rid of selected fields in $ingorefields $fieldswrapper = new InputfieldWrapper(); foreach($inputfields as $field) { if(in_array($field->name, $ignorefields)) continue; $fieldswrapper->add($field); // rebuilding the final fieldswrapper(s) to feed the InputfieldFieldset } $fs_level_2 = $this->modules->InputfieldFieldset; $fs_level_2->label = $grandchild->title; $fs_level_2->collapsed = Inputfield::collapsedYes; $fs_level_2->add($fieldswrapper); // add a submit button to the form $submit = wire('modules')->get('InputfieldSubmit'); $submit->attr("value","$grandchild->title"); $submit->attr("id+name","submit_$grandchild->id"); //1061 $fs_level_2->add($submit); $fs_level_1->add($fs_level_2); } $form->add($fs_level_1); } // Add submit button or anything else here //.... // render final form output return $form->render(); -
foreach iteration to create nested fieldset items
Federico replied to Federico's topic in Module/Plugin Development
Deleted post -
Hi all, I have to create a form in admin by populating inputfield from multiple pages. It's all fine now, except how multilanguage inputfields are displayed, because no text field is rendered. This is the tree structure - parent page -- children_01 --- Grandchildren_01_1 (this page has inputfields to be displayed in the fieldset form) --- Grandchildren_01_2 (same as above for all following grandchildren pages) --- Grandchildren_01_3 -- children_02 --- Grandchildren_02_1 --- Grandchildren_02_2 --- Grandchildren_02_3 --- Grandchildren_02_4 --- Grandchildren_02_5 This is a sketch to illustrate how the final result looks like: My code so far look like this: public function ___execute() { $page_01_reports = $this->pages->get(1038); $wrapper = new InputfieldWrapper(); foreach($page_01_reports->children() as $childs) { // loop of three pages $fieldset = wire('modules')->get('InputfieldFieldset'); $fieldset->label = __("$childs->name"); $wrapper->append($fieldset); foreach($childs->children() as $child) { // loop of final/targeted grandchildren pages $fieldset2 = wire('modules')->get('InputfieldFieldset'); $fieldset2->label = __("$child->name"); $fields = $child->getInputfields(); foreach($fields as $field) { $fieldset2->append($field); } $btn = $this->modules->get("InputfieldButton"); $btn->href = "{$this->wire('config')->urls->admin}/reports/custom"; $btn->icon = 'plus-circle'; $btn->value = "Export for $child->name"; $btn->aclass = "classeAnchor"; $btn->addClass = "pw-modal"; $btn->id = "ID"; $fieldset2->append($btn); $fieldset->append($fieldset2); } } return $wrapper->render(); } and this is the weird multilanguage inputfield as rendered in the form: Do you have any hint to give? Maybe with this? $this->page->of(false); thank you a lot
-
#colMedia is the parent div of the #mediaGrid items container, I'm calling it to append the #mediaGrid div to the #colMedia div after ajax success. I've found that probably is an IAS problem, and I'm testing some reinitialize options without success, like this jQuery.ias().reinitialize(); //or ias.destroy(); ias.bind();
-
Hi all, slightly different issue here - I'm working with a search form (multiple fields, also arrays) to filter the list of items showed in the same page. I've implemented ajax for filtering items as-you-type or as-you-select-options, which is working just fine. The only problem is the pagination: while ajax pulls items correctly within the selected container, the pagination keeps all pages as no filter form were submitted. In fact, pagination and everything else works perfectly if the form is submitted, but by getting items via ajax without "click form submit" the pagination keeps all items regardless the applied filter . here's selected code part: $("#formNews").on('change', function ajaxWorks(event){ var form = $(this); $.ajax({ type: form.attr('method'), url: form.attr('action'), data: $('#formNews').serialize(), success: function(data) { var data = $(data).find('#mediaGrid').html(); data = '<div id="mediaGrid" class="content-current" uk-grid>' + data + '</div>'; // div container // remove old content $('#mediaGrid.content-current').remove(); // scroll to the top of the page $('html, body').animate({ scrollTop: 0 }, 'slow'); // append new content to the page $('#colMedia').append(data); } }); event.preventDefault(); }); The div container contains also the pagination function, so once ajax successes, it pulls both items and the pagination into the div container. Am I forced to submit the form even though I am using ajax? thanks! EDIT: The pagination for the ajax pulled items is ok, and it works if I click on the second/next page (without form submission). Since I am using IAS Infinite Ajax Scroll, it seems that the problem is when IAS clicks on the next page ancor tag, as no URL is updated and therefore the pagination thing gets messed up..
-
Very clear @kixe! Now I understand why the buttons were redirecting me to another page instead of the modal, it was the "href" attribute instead the "data-href". Thanks a lot
-
Hi all, I couldn't find so far any post covering this, so here's the bottom line: How can you add button in custom module that opens a modal window? I know how to do it just from a custom link like this <a id="ID" href="' . $this->wire('config')->urls->admin . '/page/add/?parent_id=1039&modal=1" class="pw-modal addNewField ui-button ui-widget ui-corner-all pw-head-button ui-state-default"><span class="ui-button-text" name="button" value="Create new project code" type="button"><i class="fa fa-plus-circle"></i> your text</span></a> which opens the modal correctly, but I can't add it to the header section of the admin module (the button at the top we normally see in all pw pages) - I can only add it to the bottom of the page. Instead, using built-in button (like below) it is pw taking care of placing buttons both in header and at the bottom. The problem is that the button tag itself seems not compatible with the modal window (modal window drops after a blink). $btnAddNew = $this->modules->get("InputfieldButton"); $btnAddNew->showInHeader(); $btnAddNew->href = "{$this->wire('config')->urls->admin}page/add/?parent_id=1101&modal=1"; $btnAddNew->aclass = "pw-modal"; Suggestions?
-
Mysterious white line wireTabs
Federico replied to Martijn Geerts's topic in Module/Plugin Development
Hi @kongondo, my apologies - thanks for this I've just sorted the issue out, no need anymore the post (was just a js variable not placed correcly) - but it might help others, so I will move to a new topic. please delete it thanks -
[solved] How to add action buttons fieldtype for each repeater
Federico replied to Federico's topic in General Support
@bernhard thanks that's awesome! I was trying that attr() but eventually I discovered that if the button type="if differs from just button here, the _blank will not work" $repeaterBtn = $this->modules->get("InputfieldButton"); $repeaterBtn->attr("value", "Generate something"); $repeaterBtn->attr("type", "button"); // IF DIFFERS FROM JUST "button", IT WILL NOT OPEN NEW BROWSER TAB! $repeaterBtn->attr("id+name", "btn"); $repeaterBtn->attr("href", "/admin/page/edit/?id=1"); $repeaterBtn->attr("target", "_blank"); $repeaterBtn->addClass("customClass"); $event->return .= $repeaterBtn->render(); Thanks again both! -
Hello PW community, very humble question (not found elsewhere here, but probably I did not search deeper yet): how to pass a pages array in admin module (say array of pages IDs out of an InputfieldPageListSelectMultiple) to wirePDF, to export them in the given order and in one single pdf? Here some code // Where to pass pages array to wirePDF ? // $page = $event->arguments[0]; $pdf = $this->modules->get("WirePDF"); // Define the main markup $pdf->markupMain = $this->config->paths->templates . '/book2pdf/default.php'; // Header markup, header is only printed if you provide the markup $pdf->markupHeader = $this->config->paths->templates . '/book2pdf/_header.php'; // The same goes for the footer $pdf->markupFooter = $this->config->paths->templates . '/book2pdf/_footer.php'; // You can override any of the module config options if you have other needs, e.g. $pdf->pageOrientation = 'L'; $pdf->headerFirstPage = '1'; $pdf->pageFormat = 'A3'; $pdf->bottomMargin = 10; $pdf->author = $this->user->name; $pdf->cssFile = $this->config->paths->templates . '/book2pdf/style.css'; // Saving the PDF file to disk //$pdf->save($this->config->paths->assets.'/test.pdf'); // ... or request download $pdf->download('variable-here.pdf'); thanks in advance!
-
[solved] How to add action buttons fieldtype for each repeater
Federico replied to Federico's topic in General Support
Hi @dragan, late here just to say that after some play around hooks, I couldn't find any other way (better) than your nice snippet above. Indeed, your seems to be the most appropriate way to append buttons to each repeater (my case is in custom admin module but it involves just few changes). I will mark this tread as solved but other solution are still welcomed Beside this, I've found that the InputfieldButton doesn't have any clean option to manage the html target="_blank", as these are the options the module allows $repeaterBtn = $this->modules->get("InputfieldButton"); $repeaterBtn->attr("value", "Generate something"); $repeaterBtn->attr("type", $submitID); $repeaterBtn->attr("id+name", "btn"); $repeaterBtn->attr("data-href", "customData"); $repeaterBtn->addClass("customClass"); Maybe someone has quick n' dirt solution, probably like this one? $this->pages->addHookAfter('Inputfield::render', function (HookEvent $event) { $field = $event->object; if ($field->name === 'btn') { // add target blank } }); -
[solved] How to add action buttons fieldtype for each repeater
Federico replied to Federico's topic in General Support
Thanks @bernhard, we will see if any better implementation could fit this scenario. In the meantime, I've been playing around the runtime fieldtype as suggested by @dragan, and I think for now this is the quickest solution. btw, to get unique IDs to each button (within the Details tab), this worked for me $idUnique = $this->name; return ProcessWire\wireRenderFile('runtimeButton.php', array('idUnique' => "$idUnique")); -
[solved] How to add action buttons fieldtype for each repeater
Federico replied to Federico's topic in General Support
Thanks @dragan! as of the hook option, still I cannot find a way to hook each repeater, in order to append to them a button. I've tried this within "init()" $this->pages->addHookAfter('ProcessPageEdit::buildForm', $this, 'addButtons'); then something like this public function addButtons($event) { $page = $event->object->getPage(); if($page->template == "book2pdf"){ $form = $event->return; $accept = $this->modules->get('InputfieldSubmit'); $accept->attr('id+name', 'hook_accept_application'); $accept->class .= ' ui-priority-secondary head_button_clone'; $accept->attr('value', $this->_('Accept Application')); $form->insertBefore($accept, $form->get("id")); } } but it doesn't hook/output anything. Do you know what is the proper hook for getting each repeater one by one (then append a button to them)? this is my execute() code: public function ___execute(){ $editpage = $this->pages->get(2308); $ignorefields = array("title"); $form = $this->modules->get("InputfieldForm"); $form->method = 'post'; $form->action = './'; $fields = $editpage->fieldgroup; foreach($fields as $field) { if(in_array($field->name, $ignorefields)) continue; $inputfield = $fields->{$field->name}->getInputfield($editpage); $form->append($inputfield); } // the inputfields don't already have a submit button, so we'll add one. $submit = $this->modules->get("InputfieldSubmit"); $submit->name = "submit"; $submit->value = 'Save book'; // add the submit button the the form $form->add($submit); $out = ''; // process the form if($this->input->post->submit) { // now we assume the form has been submitted. // tell the form to process input frmo the post vars. $form->processInput($this->input->post); // see if any errors occurred if( count( $form->getErrors() )) { // re-render the form, it will include the error messages $out .= $form->render(); } else { // successful form submission, so populate the page with the new values. $editpage->of(false); // turn off output formatting before setting values foreach($form as $field) { //$editpage->set($field->name, $field->value); $editpage->set($field->name, $form->get($field->name)->value); } // save it $editpage->save(); $this->message("Book saved!"); $out .= $form->render(); } }/* if($this->input->post->ditto) { // now we assume the form has been submitted. // tell the form to process input frmo the post vars. $form->processInput($this->input->ditto); // see if any errors occurred if( count( $form->getErrors() )) { // re-render the form, it will include the error messages $out .= $form->render(); } else { // successful form submission, so populate the page with the new values. $editpage->of(false); // turn off output formatting before setting values foreach($form as $field) { $editpage->set($field->name, $form->get($field->name)->value); } $this->message("DITTO"); $out .= $form->render(); } }*/ else { $out .= $form->render(); } return $out; } Maybe the hook method itself is wrong... -
[solved] How to add action buttons fieldtype for each repeater
Federico replied to Federico's topic in General Support
thanks both!! @dragan I've created a php file with that html code and included as wireRenderFile in RuntimeMarkup - it works as expected, so thanks for the hint. Perhaps the html code needs to be integrated with php variable to host related IDs of each buttons, so eventually all buttons IDs and other attributes reflect the related repeater field. What might be the drawback of this solution, if any? @bernhard, great tutorial there, hat off! as of the button, can you please tell how the option 2 could work in the case that: - repeater is a field associated to a template (so far so standard) - the edit to the repeaters field will be made from a custom module - then, how to implement the following in such scenario? $button = $this->modules->get('InputfieldButton'); $button->value = 'Open Page in Panel'; $button->attr('data-href', './my-info'); $button->addClass('pw-panel'); $out .= $button->render(); I mean, how to properly hook every repeaters in a module and add button accordingly? Feel like I miss the basis... -
How to populate a custom module with fields from template
Federico replied to Federico's topic in General Support
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); } -
How to populate a custom module with fields from template
Federico replied to Federico's topic in General Support
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! -
Hi PW community, struggling to find a way to add custom action button fieldtype to each duplicates inside a repeater fieldtype, so for all repeater there will be a dedicated button to submit and post-elaborate related pages selection. This repeater fieldtype will be used in custom module, I thought Hooks will be my friends for this, but maybe I am wrong. Couldn't find any post for this, maybe someone could suggest a way to go Much appreciated, thank you vey much
-
How to populate a custom module with fields from template
Federico replied to Federico's topic in General Support
No worries, better wait then -
How to populate a custom module with fields from template
Federico replied to Federico's topic in General Support
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!!