-
Posts
204 -
Joined
-
Last visited
Everything posted by Guy Verville
-
Oh, thank you. It is already present for a long time!
-
Hi, We were asked to be able to manage users by role. A company has 7 branches and would like to grant permissions to branch administrators to manage the creation of users only for their branch, thus not being able to see other users. Although we can create user profiles, we would rather filter the user administration process as it exists. I wonder if anyone has ever created anything similar.
-
Hello Teppo, Thank you for your kind reply. The programmer who wrote the code just inspected it. The problem is... Google or Opera and their autocomplete feature that fills the honeypot field of the form... Since the field is fields, the form does not continue. The problem seems to be well known for ages. As for the InputfieldForm->render() not taking any arguments, I wrote above that this callback has been set in a custom render function which calls the real $form->render method. ?
-
We are experiencing a big problem with our forms. You can see them in action here: https://www.centura.ca/en/my-centura/sign-up Since the Retailer form is the most used for the moment (the site is in soft launch), I will discuss this one. When a retailer signs up, the callback creates a profile and a user. The form is rendered with this code: return $_form->render($form, function($form, $template) { return $this->createUser($form, $template, true); }); The callback is, of course createUser. This callback has been set in a custom render function which calls the real $form->render method. public function createUser(InputfieldForm $form, \TemplateEngine $template, bool $notify = false): \TemplateEngine { $form = $this->validateCreateUserForm($form); if(count($form->getErrors()) > 0) { return $template; } [...] $_form->setMessage(__("Your request has been sent to Centura for validation. We will contact you as soon as possible.")); wire("session")->redirect($_SERVER["REQUEST_URI"]); [...] return $template; } The callback is performed as requested for most of the users. And then, it is not fired for apparent no reason and users complain. They are reverted back to their form, already filled. They then try to send again the form to be redirected again with the form without any other indication of something going on. In the backend, nothing is performed. I was able to reproduce the problem. Using Tracy Debugger, I placed some bdb() calls in the createUser callback to realize that it is not fired at all! Then I discovered that opening a new window in furtive mode resolved the problem. I was able to send my form. All the bdb() calls were fired and the user was created as planned. I have checked for console errors, server errors, etc. Nothing. The redirecting code that was first written by the programmer was: header('Location: '.$_SERVER["REQUEST_URI"]); I decided to with the wire("session") equivalent, but to no avail. We seem to experience this problem with Chrome or Opera. But I can't be sure of that at that point. Any idea?
-
Adding an image to a Repeater Matrix Field
Guy Verville replied to Guy Verville's topic in Getting Started
Thanks a lot, it works. -
Adding an image to a Repeater Matrix Field
Guy Verville replied to Guy Verville's topic in Getting Started
Thank you for answering. I did that before, but it's not working. Still the same error. Given: Site accepting the request: mq.local Site where the file resides: afmq.local $responseAdded['imageURL] = http://afmq.local/site/assets/files/1862/img_0729.jpg Since the url given is outside mq.local, should I download the file before? -
Hi, I'm trying to simply save an image contained in a Repeater Matrix field. But I get an error with this code: $added = $p->member_mx_images->getNew(); $added->member_images->add($responseAdded['imageURL']); $added->crm_products_sold = $products; $added->save(); $p->of(false); $p->member_mx_images->add($added); $p->save(); The error is: Call to a member function add() on null at the line $added->member_images->add($responseAdded['imageURL']); member_images is the image field. If I remove the add instruction, nothing is saved. $responseAdded['imageURL'] is a valid address coming from and external site (my purpose is to make two Processwire sites communicate certain information). crm_products_sold is a Page reference field. $products is an array of IDs. If I remove the instruction for member_images, I do get a repeater saved, but it is empty anyway. I don't know what I am doing wrong.
-
$sanitizer truncating text field - defaults are set where?
Guy Verville replied to Smoo's topic in Getting Started
See all the options available here: https://processwire.com/api/variables/sanitizer/ -
Save a page reference field in a RepeaterMatrix
Guy Verville replied to Guy Verville's topic in API & Templates
It's a false alert. I was compare the page field to itself. However, to be able to update a page reference, you have to set it to null before. If not, the pages are added. $changed = $p->member_mx_images->eq(array_key_exists($responseChanged['basename'], $indexMxArray)); $changed->of(false); $products = explode(',', $responseChanged['products']); $changed->crm_products_sold = null; $changed->crm_products_sold = $products; $changed->save(); And we do not need to save the page where the mx_field belongs to, because the variable $changed is in itself a page. -
Hi, I must change via API a field called member_mx_images that includes an image and a page reference field called crm_products_sold. I have tried a lot of things but to no avail. I based my code along: https://processwire.com/api/fieldtypes/repeaters/ The code below shows $changed which is the repeated I must change. $products is an array of page IDs. $changed = $p->member_mx_images->eq(array_key_exists($responseChanged['basename'],$indexMxArray)); $products = explode(',',$responseChanged['products']); $changed->crm_products_sold = $products; $p->of(false); $changed->of(false); $changed->save(); $p->save();
-
You bet, our Quality Assurance department was very happy to discover that! While a lot of website do not require unit testing, we try to implement those with our more complex websites.
-
Thank you, it was the problem!
-
Sure! Of course, $path should be a valid path in your website. <?php namespace ProcessWire; use \Tester\Assert; use \Tester\TestCase; /** * @testCase */ class GetOtherSiteResponseTest extends TestCase { public function getOtherSiteConnectionTest() { $config = wire("config"); $http = new WireHttp(); $path = "http://" . $config->afmqOtherSite . " /en/afmq-services/hello/"; $response = $http->get($path); $expected = "Succès!"; $actual = $response; Assert::equal($expected, $actual); } } (new GetOtherSiteResponseTest())->run(); The code of the template that responds is simple (this is crude test. I am using Twig templating). <?php namespace ProcessWire; require_once "MainController.php"; /** * Class AfmqServicesController * @package ProcessWire */ Class AfmqServicesController extends MainController { /** * Simple test * * @return void */ public function render(): void { $view = wire("view"); $input = wire('input'); $urlSegment = $input->urlSegment1; switch($urlSegment){ case "hello": echo "OK"; exit(); break; default: exit(); break; } } } (new AfmqServicesController())->render();
-
Hi, I have some problem configuring a test with wireHttp involved. This code works ok on a real template (called testPageController.php). I have two local sites to make the test. public function getOtherSiteConnectionTest() { $config = wire("config"); $http = new WireHttp(); $chemin = "http://" . $config->afmqOtherSite . " /en/afmq-services/hello/"; $response = $http->get($chemin); $expected = "hello"; $actual = $response; Assert::equal($expected, $actual); } Nette Tester tells me it has forgotten to make the test which means a misconfiguration of a sort. What I did wrong?
-
trackChanges does not track everything of an object?
Guy Verville replied to Guy Verville's topic in General Support
Hi Zeka, Unfortunately, changing to $existingPage->setTrackChanges(Wire::trackChangesOn | Wire::trackChangesValues); does not worked. I realized though that putting true in getChanges, gives me an array of all the values of the field. $changes = $existingPage->getChanges(true); $implodedChange = ""; foreach($changes as $key => $change){ $implodedChange .= $key . "=>" . implode(",",$change) . "<br/>"; } However, the $existingPage->parent_id is still not caught... I think I will have to track this with my own code. -
Hi, I thought I understood $object->trackChanges() behavior, but I am not so sure now. The code below if($p->parent_id != $dataBundle["parent"]) { $p->parent_id = $dataBundle["parent"]; } or this one $p->setLanguageValue("francais", "crm_description", $data['DescriptionFrancais']); is not recorded, while this one is $p->crm_description = $data['DescriptionEnglish']; I try to make a log file for a synchronization process with this code: $message = "<p><a href='$existingPage->httpUrl'>" . $existingPage->title; $message .= "</a> a été modifié (" . $existingPage->template . "). Changements aux champs => "; $messag .= implode("<br/>", $existingPage->getChanges()); Any idea?
-
That's why I asked... We did just a great project (https://centura.ca) and we have a lot of page references (it was not coded by me, and the guy is absent for the moment, and his code is not different from mine...). There is indeed such a field that is supposed to be automatically completed. Maybe I am just too tired of trying.
-
I don't know why I was on the impression that there was an API way (no pun intended).
-
PHP generator class and $pages->find()
Guy Verville replied to Guy Verville's topic in General Support
I was under the impression that findMany() was loading everything into memory. Maybe I'm wrong... I will do some tests, thanks. -
First of all, I'm not an expert on PHP. I recently read about generators and I understand their usefulness in avoiding loading a set of objects into an array to the point of saturating the memory. The $pages->find() call is known to be greedy (and slow) when it comes to processing large amounts of pages, because it loads all objects into memory. Is there a way to use a generator to avoid this problem? Is there a workaround? I know that $pages->findMany() exists, but it is also called greedy. See https://secure.php.net/manual/en/language.generators.php Translated with www.DeepL.com/Translator
-
Thank you very much for this nice addition! I will give it to my programmer (he had created his own solution inspired by your module and tightly integrated wit the existing code, but your config approach is more convenient and will certainly help a lot of people here). PS: I have installed in my modest and personal website and works like a charm. http://www.guyverville.com/sitemap.xml
-
Hi Mike, Thank you for your excellent module. A wish : we have a big website where product pages are stored under a parent (a series => parent: series-carpet, children: sku-carpet, this is handy for our client to see the SKUs associated to a collection). These children are not hidden for search purpose, but are hidden from the navigation and, hence, from search engines. Your module generates for that site a 10000 sitemap list because the children are included. We can't go from series to series to disallow the sitemap generation for the children. In other words. Your module allows us to include/exclude sitemap generation for actual pages. It would be very convenient to disallow/allow a sitemap for a whole template from the template settings.
-
I found the culprit. I commented out the RewriteBase / line in my htaccess... # ----------------------------------------------------------------------------------------------- # 11. OPTIONAL: Set a rewrite base if rewrites aren't working properly on your server. # And if your site directory starts with a "~" you will most likely have to use this. # ----------------------------------------------------------------------------------------------- RewriteBase /
-
Thank you Adrian, The problem resides on my prod site, hosted by Greengeeks. I have changed nothing there. Perhaps they? I use MAMP Pro on local and everything is fine.