Smart quotes problem

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
graham
Veteran Member
Posts: 88
Joined: 2020-09-29 12:30

Smart quotes problem

Post by graham » 2024-09-12 09:49

Hi, I'm getting problem with people pasting in text that contains 'smart quotes'. (i.e. ' pasted from Word - ‘hello’) My question is, is there a master place in the code where I can perhaps add a catchall mysqli_real_escape_string so that when someone copies and pastes, say This is ‘some’ text - using smartquotes instead of keyboard quote it doesn't error? Or is there a better answer? Any thoughts appreciated. Thanks.

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 355
Joined: 2013-03-21 04:37

Re: Smart quotes problem

Post by peebee » 2024-09-13 06:00

I recall I've struck this problem before and am pretty sure I fixed it with javascript at the time of pasting, triggered by an event listener.

This is untested but you could try the following.

Assuming it is all <textarea> elements you are having problems with, you could try adding the script below to your hooks/header-extras.php

Code: Select all

<script>
    // Listen for any input event on textareas within the document
    document.addEventListener('input', function(event) {
        // Check if the event target is a textarea
        if (event.target.tagName === 'TEXTAREA') {
            const textarea = event.target;

            // Replace smart double quotes (“ ”) with straight quotes (" ")
            textarea.value = textarea.value.replace(/[\u201C\u201D]/g, '"');
            
            // Replace smart single quotes (‘ ’) with straight quotes (' ')
            textarea.value = textarea.value.replace(/[\u2018\u2019]/g, "'");
        }
    });
</script>
Hopefully that should work.

(for <input> elements, just replace the TEXTAREA tagName with INPUT .....etc)

graham
Veteran Member
Posts: 88
Joined: 2020-09-29 12:30

Re: Smart quotes problem

Post by graham » 2024-09-13 07:41

Thank peebee, I can see why that should work and just tried it but without success. I'll try and tweak it but if anyone can spot what's stopping it from working I'd be happy to hear. Thanks. Graham

ppfoong
Veteran Member
Posts: 52
Joined: 2021-07-13 16:46

Re: Smart quotes problem

Post by ppfoong » 2024-09-13 13:46

I think smart quotes shouldn't be an issue, is it because the locale (character encoding in AppGini project page) you are using is not unicode?

Post Reply