Jump to content

Add an allowed character to default seach form. [solved]

Recommended Posts

Hello, and thanks again for PW. The more I use it, the more I like it.

I have a silly problem, and since I have tested several (bad) solutions, I come and ask for help. I think I'm just being thick there...

Is there a relatively simple way to add an allowed character to the default search form's sanitizer ?

FYI, I'm working on a dictionary in breton language (60k entries), and I must find a way to allow apostrophes in search input. (In breton language, "CH" and "C'H" are actually two different letters altogether).

I must say I'm a bit confused by the sanitizer. On the regular search form, it appears three times. Once in the input field itself, and twice on the search template.

I did read the sanitizer page and sanitizer class page, but I'm not sure to understand where to go from there. From what I understand, the


methods would accept some extra allowed character, but I seem to have no luck in adding this to my template. Morevover, do I have to change any sanitizer call to a -> name one ?

The sanitizer php core page includes an "allowedASCII" which seems very promising, but is there a way to override it ? Hooks ? (not used to them I'm affraid...)

Morevover, the fact that i'm trying to implement the (') character worries my a bit. Can I escape it ? would something like '\'' do the trick ?

Thank in advance to you, good men. The site building is reaching an end, and I am tired indeed. (you wouldn't believe the state of the initial DB I had to work from...)

Share this post

Link to post
Share on other sites

I don't think sanitizers will be the kicker here, but rather which characters are supported by processwire's selector engine and/or mysql's handling of those characters. I'm not sure, but $sanitizer->selectorValue might give at least some insights.

Share this post

Link to post
Share on other sites

Well... Thank you for the tip. Might well be, however, I have been looking at selectorValue, and it actually seems to handle apostrophes. (I might be wrong here)

However, Alice would say thing are getting curiouser and curiouser... If I echo my $q and $selector on the search page, and test with a "c'hai", for instance, I do get "c'hai" printed. So the apostrophe might indeed survive the sanitizers.

However, when I try to echo a

$pagechai = $pages->get("title=c'hai");
echo "<p>test appel:{$pagechai->name}</p>";

i get nothing, even if I try a title=c\'hai

Hmmm... Maybe this has some deeper root than a simple sanitizer. Does PW clean direct calls to it's pages titles ? Thiscould be a problem in my specific case. ^_^

Share this post

Link to post
Share on other sites

That pages find works here. Not sure why it's not working at your end. What version of PW are you running? Anything unusual with your server setup that you can think of?


  • Like 1

Share this post

Link to post
Share on other sites


OK. First, thanks for checking. This will definitely spare me hours of pain. Definitely from my end. (I prefer this...)

Processwire is 3.0.42. Only "weird" thing I can think of on my dev server is PHP 7.0 (I will try with 6)

Oh, and I started with a blank profile and just copied the search page from default profile when I needed it. (don't ask me...), although searches mostly work.

Must be some misconfiguration somewhere in my settings. I'll try and start fresh in the morning.

Thank you very much, I would probably have lost hours before thinking of trying on a fresh install. I'll let you know if I discover what is the cause of this.

Share this post

Link to post
Share on other sites

I am running PHP 7, so don't worry about that.

I am running the latest PW dev 3.0.57, but I doubt there'd be an issue in 3.0.42, but maybe worth checking.

Did you go with standard MyISAM and UTF8 in your MySQL database? I don't think this should be an issue either, but just something to check.

Share this post

Link to post
Share on other sites

UTF8 and MyISAM, yep. MySQL standard from ubuntu repos.

But you might be right, now that you mention it, I can have reasonable doubts about my SQL config. I had to do some dirty things in order to recover data from a massive pile of sugar a while ago. 

I will try to dump this on another server tomorrow. It was planned anyway. Then I'll be sure.

Thanks for the head up. I'll let you know if I have any luck.

Share this post

Link to post
Share on other sites


Note for later : sleeping is sometimes useful.

So it eventually had nothing to do with PW search nor sanitizer. It was more about me being a moron.

This came from libreoffice not inserting the correct apostrophe character in the source data sheets. A simple search and replace in my original CSV will sort this out (I had to change a few things anyway).

Thank you all, folks, I could have lost hours before thinking of checking the source material. (as I should probably have done first....)

  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By stanoliver
      Hi! I tried to implement a simple site search like in the regular site profile by Ryan.
      I checked out the code on github but I could not make it work for my site. Probably because Ryan uses some advanced output strategy and uikit specific stuff which I don't use or understand.
      For my site I just use:
      - 1 template (name: templatetoparea.php) for the toparea of my site
      - 1 template (name: templatemainare.php) for the main content of my site
      - 1 template (name: templatefooterarea.php) for the footerarea of my site.
      Also I have prepared two empty templates:
      - 1 template (name: templatesearch.php) for the search itself
      - 1 template (name: templatelistsearch.php) for listing the search results
      May somebody could let me know how to implement a very basic site search like in the regular site profile without using any module or complicated output strategies.
      Two things would be a must have:
      - The search should work with standard repeaters (where most of my content lives)
      - The search results/hits should be listed and the search word(s) should have a yellow colored background (inline css is fine) 
    • By VeiJari
      Hello forum!
      I've yet again stumbled on a head-scratching situation. We have enabled the option on our articles template and events template that it skips the title adding part and goes straight to the form. This is what our customer wants. So when you add a new article or event it automatically names it temporary to "article-0000000" and same with event. Now the problem is that obviously after saving the form we want to change to page url or "name" to the title, like it's normally. 
      Now here's the code for the hook:
      wire()->addHookBefore("Pages::saved(template=tapahtuma|artikkeli)", function($hook) {
        $page = $hook->arguments(0);
        $newUrl = wire()->sanitizer->pageName($page->title); // give it a name used in the url for the page
        $page->setAndSave('name', $newUrl);
      I get the correct page and the name and path changes when I log them, but when I try to save it. It just loads and then I get: 
      Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) This happens in sanitizer.php
      and then another error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0
      What is happening? Am I not suppose to use sanitizer in this way? When we made a temporary page object in out other hook, the sanitizer worked perfectly.
      Thanks for the help!
    • By Robin S
      A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...
      Sanitizer Transliterate
      Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.
      Install the Sanitizer Transliterate module.
      Customise the character replacements in the module config as needed.
      Use the sanitizer on strings like so:
      $transliterated_string = $sanitizer->transliterate($string);
    • By slave
      I would like to create a search form with a category selection.
      I do not get the selector, I need help
      my selector
      $katId = $pages->find("template=leftnav_kat, h1_h6_1%=$kat"); its ok
      $matches = $pages->find("template=site, has_parent=$katId"); its ok
      myresult this pages (templates = site):
      MedLab ML +2 °C bis +8 °C 41 Liter
      MedLab ML +2 °C bis +8 °C 41 Liter
      MedLab ML +2 °C bis +8 °C 45 Liter
      MedLab ML +2 °C bis +8 °C 82 Liter
      MedLab ML +2 °C bis +8 °C 82 Liter
      LabStar Sanguis +2 °C bis +6 °C 100 Liter
      MedLab ML +2 °C bis +8 °C 107 Liter
      LabStar Sanguis +2 °C bis +6 °C 100 Liter
      MedLab ML +2 °C bis +8 °C 82 Liter
      but I'm looking for a text in the template = site, this template has a field search_cache

      $katId = $pages->find("template=leftnav_kat, h1_h6_1%=$kat"); its ok
      $matches = $pages->find("template=site, has_parent=$katId, search_cache%=Industrie"); not work
      I need help

    • By Noel Boss
      To create a new gitlab issue, I'd like to send an Email to the following email address using FormBuilder: 
      unfortunately, the / in the email gets striped by the sanitizer:
      wire('sanitizer')->email(incoming+account/repository@incoming.gitlab.com'); // output: incoming+accountrepository@incoming.gitlab.com Is there any way to configure the sanitizer? Any other Ideas how to send the mail to this address?
      Ps.: I can not define the email format as it is defined by gitlab. The format is also kind of "common" and known as email-alias in the form of emailaccount+alias@domain.com – gmail uses it to label mails…
  • Create New...