Federico

Members
  • Content count

    84
  • Joined

  • Last visited

Community Reputation

11 Good

About Federico

  • Rank
    Full Member
  1. You're right - After some tests, I've move the code into execute() and now I see the message "Ajax post received" in Response. Now I better understand the function executeTesta() linking to another page (a page that doesn't even exist actually..), so I was likely trowing away the ajax submitted POST. Is the execute() the correct location for this code? thanks!
  2. 1 - the form is submitted via ajax on the same page (It is an admin process module), therefore the path should be log-in/ProcessModuleName/ 2 - I've tried both version, I didn't recognized any difference. But I agree that url:"./" should be better than just url:"" 3- If I echo something within the executeTesta() function, I will see it in the panel (pw-panel). Actually in the panel I see all php code, excluding the possibility to retrieve any ajax POST variable 4- that' was just to see if it was empty or containing something, just a test for development purpose.
  3. @kongondo I've tried also your code into the function (this function lies in the same .module file) public function ___executeTesta() { $sanitizer = $this->wire('sanitizer'); if ($this->wire('config')->ajax) { // ajax sent, process inputs $input = $this->wire('input')->post; return $input; } } to test if any variable is taken from PHP after ajax submission, but no luck. I see POST variable in Tracy, but I cannot retrieve them. Maybe is because I am opening the ajax call in the pw-panel? or maybe because the "url" in $ajax POST is set to none ("")?
  4. All, there are many post already in the forum that describes how to deal with form submission trough ajax post in the same module page. However, I cannot retrieve POST data after ajax submission - here is my jquery: $( document ).ready(function() { $('.button_export2pdf').on('click', function (e) { var buttonClickedID = this.id; if (buttonClickedID) { var completeData = buttonClickedID + $("form").serialize(); $.ajax({ type: 'post', url: "", // empty as it is the same page data: completeData, success: function(data){ //alert(buttonClickedID); } }); } }); }); and this is the php code inside the same process .module file: // relevant section of the form code $form = $this->modules->get("InputfieldForm"); $form->method = 'post'; $form->action = './'; // relevant section - the button to submit the form trough ajax $repeaterBtn = wire('modules')->get("InputfieldSubmit"); // leave as submit button for export in new tab $repeaterBtn->attr("value", "Generate Brochure in tab"); $repeaterBtn->attr("id+name", "button_form_$field->name"); $repeaterBtn->addClass("ui-priority-secondary button_export2pdfTab"); $repeaterBtn->addClass('class-here'); $repeaterBtn->attr("target", "_blank"); // leave this, but the "open new tab" job is made by jquery $form->append($repeaterBtn); // relevant section - the function to fires after button click public function ___executeTesta() { // OK, THIS FUNCTION ACTUALLY FIRES WHEN USER CLICK THE ABOVE BUTTON //include("./includes/test.php"); return $this->input->post->completeData; // WHY THIS IS ALWAYS EMPTY??? echo isset($_POST['data']) ? $_POST['data'] :''; // NOT WORKING } And this is the results from the Tracy Ajax call, which actually displays the correct POST values.. Can you please give me an hint why I cannot retrieve any info from the ajax submitted data? Thanks a lot!
  5. @flydev I've tried with different variable than $page, same results. Please note that ["page" => $item] inside the above foreach loop works correctly if I submit the form, as the pdf is generated correctly in the new browser tab, with all $page as $items taken from the the pageArray. I mean, all php functions are working OK when the form is submitted, but I can't submit the form on a modal window. The point here is that if I add pw-panel to the button class, then the foreach loop doesn't even fire, totally skipped! so I guess the following argument: - The pw-panel and pw-modal windows don't let php foreach to fire (most likely because there is no real form submit), they both work just fine with only direct php statements. Moreover, $page variable is just the current module page.
  6. @dragan it is for a custom admin module. the name of the clicked button references to its relative repeater, as any repeater has its own button
  7. Stuck with pw-modal / pw-panel opening of generated pdf. I have a pageArray containing selected pages, if I export the array in pdf from the current page (thus replacing the custom module page), it is all fine and correct. If I use the same setting and try to export the pdf in modal window (by adding pw-modal in the button), well the modal window pops up but it show the frontend website 404 page, whereas in panel window (by adding pw-panel in the button) the pdf is rendered in panel but with missing pieces (not reading the $page instance!). this is how I send the page array to feed the pages2pdf module: foreach($pageArray as $item) { $pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/default_panel.php', ["page" => $item]); } therefore the problem is that even though I state ["page" => $item] from the pageArray, only in both modal and panel windows the $page variable in foreach loop is just the current module page! @Wanze do you know why I cannot pass the pageArray to the pages2pdf to feed the modal/panel window? thanks
  8. 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
  9. 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!
  10. 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
  11. 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
  12. 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
  13. @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
  14. 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();