Jump to content

Federico

Members
  • Posts

    106
  • Joined

  • Last visited

Everything posted by Federico

  1. Thanks @Zeka and @bernhard for some reasons the code posted by Bernard gives an error, even if starts with $this->wire->addHookAfter instead of just $wire->addHookAfter maybe because the form name declaration in this method (I did not know, can you actually declare the form name in that?) InputfieldForm(name=form-application)::processInput Anyway, I have solved this minor issue with the approach as per the Zeka suggestion. Thank you both
  2. Hi @Zeka In the code above I have the POST input check, as follow: if($this->input->post->hook_accept_application){ wire('session')->redirect(wire('pages')->get(123)->editUrl; } which works. However, for a more articulated module development I am looking for a hook method to fire a function when the form named "form-application" is submitted. In other words, I am looking to wrap it into a function like the following one. Any idea? public function addButtonsMethods($event) { if($this->input->post->hook_accept_application){ wire('session')->redirect(wire('pages')->get(123)->editUrl; } }
  3. Hi, here is my attempt in short. I want to hook the submitted form in custom admin module and fire a function if conditional applies. Problem: I cannot find a working hook to check if a form has been submitted. I would like to fire the addButtonMethod function if the form "form_application" is submitted by the "hook_accept_application" button. I know it sounds basic, but I have tried all of the following without success. Thanks a lot for the help public function init() { parent::init(); $this->addHookBefore('InputfieldForm::processInput', $this, 'addButtonsMethods'); $this->addHookBefore('InputfieldWrapper::processInput', $this, 'addButtonsMethods'); $this->addHookBefore('InputfieldSubmit::processInput', $this, 'addButtonsMethods'); } public function ___execute() { $modules = $this->wire('modules'); $form = $this->modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name", "form_application"); $btn_application_create = $this->modules->get("InputfieldSubmit"); $btn_application_create->attr('id+name', 'hook_accept_application'); $btn_application_create->value = "Start Student"; $btn_application_create->addClass("ui-priority-primary button_submit"); $form->append($btn_application_create); return $form->render(); } public function addButtonsMethods($event) { if($this->input->post->hook_accept_application){ wire('session')->redirect(wire('pages')->get(123)->editUrl; } }
  4. Just a quick question, as I wasn't able to find any answer over this tread: is the scf module capable of manage file uploads (therefore send email with attachments)? Because my form gets error as soon as I attach a fileUpload fieldtype to the form, so no way for me to manage it Much appreciated
  5. Hi, is there a clean way (not touching the module) to get fields labels instead of fields name in the email content text? //Line 464 foreach ($this->allFields as $inputfield) { $message[] = $inputfield .': ' . $this->sanitizer->textarea($this->input->post->{$inputfield}); } to something like this (not working...)? //Line 464 foreach ($this->allFields as $inputfield) { $message[] = $inputfield->label .': ' . $this->sanitizer->textarea($this->input->post->{$inputfield}); } thanks! --- Amendment: Here's how I've approached to get this done, maybe someone else might be interested: $message = array(); $message[] ='Some description...'; $message[] = '---'; $message[] = 'Name Surname: ' . $input->post->mail_name; $message[] = 'Partecipa il 7 Luglio? ' . ($input->post->mail_option_01 == 1 ? 'Si.' : 'No.'); $date = new \DateTime(); $message[] = 'Date: ' . $date->format('Y-m-d'); $emailText = implode("\r\n", $message); // in option array 'emailMessage' => $emailText, Cheers!
  6. @elabx that's great, I've just tested in ready.php and it works as expected. Good hook! I was getting close to this but I didn't know about the possibility to ad executeSomething right in the hook method. Thank you!
  7. Hi there, adding a function in ready.php (like I normally do in custom module) throws an error, for obvious reasons. How can I implement a hookable url within the ready.php (admin side)? for instance, if I hook a pageLister execution to add a button to it like this: $wire->addHookAfter("ProcessPageLister::execute", function($event) { if(wire('page')->id === 1413) { // the particular Lister instance page id $out = $event->return; $out .= ''; $btn = wire('modules')->get("InputfieldButton"); $btn->attr('data-href', "./addNewRecordal"); $btn->addClass("pw-modal"); if(!$this->config->ajax) $out .= $btn->render(); $event->return = $out; } } How can actually create a virtual url for that button? in a custom module it can be achieved like this: public function ___executeAddNewRecordal() { // // Create new page and redirect to its edit section $p = new Page(); $p->template = '02_template'; $p->parent_id = 1040; $p->name = 'recordal_' . $pageRecordalsMicrotime; $p->title = 'Recordal_' . $pageRecordalsMicrotime; $p->created_users_id = $this->user->id; $p->of(false); $p->save(); $this->session->redirect(wire('config')->urls->admin."page/edit/?id={$p->id}&modal=1"); } ..but in ready.php this is not possible. The tricky thing is that I have to hook a modal, I think, and this is not achievable via PHP afaik. Any hint? thanks
  8. Hello, I'm sure it requires a simple hook to hide the entire Pages tab in admin (for non-superusers), but none of the post in this forum nor the hooks directory seem providing an answer as far as I know. looking for adding the hook in ready.php, like this example $wire->addHookAfter('Page::listable', function(HookEvent $event) { // BUT I AM LOOKING TO HOOK THE ENTIRE TAB CALLED PAGES, NOT JUST THE LIST INSIDE $page = $event->object; $user = $this->user; if($this->wire('user')->hasPermission('example')) { $event->return = false; } }); someone more experienced? thanks a lot
  9. Hi @bernhard, my use case is to find this type of hook for the main navigation and prepend or append something to it. In Reno Admin theme (but also in the default admin theme too) we could achieve this with the following code $wire->addHookAfter('AdminThemeRenoHelpers::topNavItems', function($event) { $out = $event->return; $out .= '<li><img src="path/image.png"></li>'; $event->return = $out; }); Whereas you cannot leverage a similar hook to the Uikit theme (the latter soon to be the default theme). Am I correct?
  10. Hello pw community, is it possible to add some hook functions to the Uikit theme as well? I see all others themes (default and Reno) have extensive hooks capabilities, whereas the Uikit based theme in the admin has only the ___breadcrumb available. I am looking specifically to hook the masterhead navigation, but I believe the array of requests might be larger. I was discussing this on another thread @ryan sorry to bother you, maybe you already gave it some thoughts about. Do you think this will require intense work? Thank you very much!
  11. At the moment the only way to achieve this in the Uikit Admin Theme is via javascript route, as described by Lahijani in this thread
  12. well after many attempts, I've found that this working solution doesn't work for the Uikit Admin theme, as the latter has no helper file (yet, whereas all others admin theme have). pity!
  13. Looking for suggestions on how to insert a dropdown menu next to the admin navigation (Pages, Setup, Modules, Access, DropdownMenu), with uikit3 will be something like this one I see how to hook and modify the module page title and the breadcrumb $this->addHookBefore('Process::execute', function (HookEvent $event) { $process = $event->object; $event->wire('breadcrumbs')->removeAll(); $event->wire('processHeadline', 'customTitle'); $event->wire('processBrowserTitle', 'customTitle'); }); but not sure how to hook the main navigation to add new item. I see this executeNavJson in the Hooks methods, but doesn't return enything $this->addHookBefore('Process::executeNavJSON', function (HookEvent $event) { $process = $event->object; // @var Process $process bd($process); // Tracy is not even thrown }); Did I miss any docs for this?
  14. Hi there, sorry for raising this up, but I think it is not entirely correct to leave this as "solved", because I've just discovered that all the hook code above will actually add new <form> tag for each repeater, leading to a code mess and nested forms.. $this->pages->addHookAfter('Inputfield::render', function (HookEvent $event) { //$page = $event->arguments(0); $field = $event->object; //substr takes the first 13 letters to match the repeater_item if (substr($field->name, 0, 13) === 'repeater_item' && $this->page->name === 'book') { $id = str_replace('repeater_item_', '', $field->name); $form = wire('modules')->get("InputfieldForm"); $repeaterBtn = wire('modules')->get("InputfieldButton"); $repeaterBtn->attr("value", "Generate Brochure in panel"); $repeaterBtn->attr("type", "button"); $repeaterBtn->attr("id+name", "button_form_$field->name"); $repeaterBtn->attr("data-href", "./testa/"); $repeaterBtn->addClass("ui-priority-secondary "); $repeaterBtn->addClass('pw-panel button_export2pdf'); $form->append($repeaterBtn); $myForm = $form->render(); $event->return .= $myForm; } }); by calling Inputfieldform here, eventually the module will load these new button in a new form tag, the latter nested into the main form tag room for improvement?
  15. Thanks @BitPoet, I see the point of the regular page load on the iframe via data-href link. Could you be more specific on how deal with pw-panel via ajax? I think it will be useful also for others pw users. I have this ajax call which simply returns all form values. How do you manually fire such panel/modal request via ajax? $.ajax({ type: 'post', url: "./customPage/", data: $("form").serialize(), success: function(data){ //$("#form_book").html(value); //alert(buttonClickedID); } }); Maybe on a success function?
  16. Hi there, no post all over the forum, which seems strange to me given the relevance. I have a custom admin process module with a need of displaying in panel window the form submitted values trough ajax. in essence the pw-panel and pw-modal windows when opened they only read non-ajax conditional, therefore the following code in pw-panel will output only "no ajax" $out .= ''; if ($this->wire('config')->ajax) { foreach($this->input->post->ClickedRepeaterID as $key => $value){ $p = $this->pages->get($value); $out .= $p->title; $out .= "yuppy, Ajax here!"; } } else{ $out .= "I am afraid, no ajax here"; } return $out; Do I miss something? thank you very much
  17. 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!
  18. 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.
  19. @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 ("")?
  20. 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!
  21. @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.
  22. @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
  23. 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
×
×
  • Create New...