1

I recently created a plugin for Joomla which uses the nice SweetAlert2 popup script and it generally works fine. However, surprisingly, when the size of the html message I use is too long, the box does not popup and the content gets instead written to the document body itself. Is there a size limit for the html parameter or could this somehow be caused by Joomla?

  • No, I did not yet isolate how many characters it fails but I will.

  • No, I did not dig into SweetAlert2's code as it goes way beyond what I can do with javascript.

  • Yes, I checked the miniorange plugin but it was not really what I needed.

  • Here's the code for the part where I check the html parameter (note that I had to try to deal with accented characters too).

    /**
     *
     * Create content 
     * 
     * Parameters-values separators is :=
     */
    function generateText($array)
    {
        $res =explode(",",$array);
    
        // For each parameter
        // we extract value
        foreach ($res as  $str)
        {
            $s = explode(":=", $str);
            // Test apostrophe
            if ($s[0] == 'html' || $s[0] == 'text')
            {
                //$s[1] = trim($s[1],"'");
    
                if (strpos($s[1],"l'") !== false)
                {
                    $accents = str_replace("l'","l\'",$s[1]);
                    $string = "'" . $accents . "'";
                }
                else
                    $string = $s[1];
            }
            else
                $string = $s[1];
    
            // In case there's html, decode to keep tags
            $corr = html_entity_decode($string);
            // Add to final text
            $texte .= $s[0] . ":  " . $corr .",";
        }
        // Remove last two chars
        $new = substr($texte, 0, -1);
    
        return $new;
    }
    

:= is the separator and the plugin syntax is like:

{swal title:='<span style="font-size: 16px;">INFORMATION</span>',html:='<span style="font-size: 14px;">Mask and sanitary pass are</span><b><span style="font-size: 14px; color: #FF0000;"> mandatory for all adults and kids from 12 to 17 to....</span></b><br /><br /><b>Thanks!</b>',icon:='info',confirmButtonText:='OK',iconColor:='#FF0000'}{/swal}
7
  • Please take our tour while you wait for feedback/support. Did you dig into the code yourself to hunt for clues? Did you isolate how many characters are required to trigger the bug? Did you know about plugins.miniorange.com/joomla-sweet-alert before creating your own plugin? May we see the vital parts of your custom plugin? What html element receives the excessively long text? Please edit your question is you can provide any of these details.
    – mickmackusa
    Dec 2, 2021 at 12:13
  • Honestly, there isn't much worth keeping in your snippet. I don't mean to be rude, but there is much to fix and refine. Please show me a few examples of examples of input strings and your exact desire return value for each input. This way I can craft something a bit more professional for you.
    – mickmackusa
    Dec 4, 2021 at 12:48
  • A variable called $array should never contain string-type data.
    – mickmackusa
    Dec 4, 2021 at 12:49
  • Without being able to test, I'd say that $string = "'" . $accents . "'"; will be breaking the SweetAlert's parsing code. I assume that it is looking for single-quote wrapped substrings, but you are mangling the substrings whenever l' is found. Is this the goal: 3v4l.org/QiGci ?
    – mickmackusa
    Dec 4, 2021 at 20:30
  • Hello again. Thanks for helping out. Forgot to say that php is not my main skill as you figured...Yes, your sample is probably what I need. I'll try to see what happens and I'll also probably stay away from php in the future :) Dec 5, 2021 at 9:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.