The horrors of frames

    Date: 08/29/07 (Web Development)    Keywords: php, browser, web

    I've always avoided using frames up til now, but I've recently had to implement a form spell checker script on a site I'm working on, and it's causing me grief. The code for the actual display is as follows:


    " marginwidth="0" marginheight="0"
    scrolling="auto" frameborder="0" border="0">
    " marginwidth="0" marginheight="0"
    scrolling="auto" frameborder="0" border="0">
    <br /> <h2>You must have frames enabled in your web browser to use the spell checker.</h2><br />


    The problem I'm getting is that the text displayed (i.e., the bit being checked) refuses to fill the window properly. Instead it forms one long line of text so that it has to be scrolled along. I've tried turning scrolling off, but it still displays in the same way - the only difference is that you can't read the rest of it. I've also tried adding frameset cols with a fixed width, but to no effect. The most frustrating thing is that as it loads, the text displays as I'd like it to, fitting nicely into the popup window, but then changes its mind. If anyone has any thoughts or suggestions, I would really appreciate the help!



    spellchecktest.php:



    if (!isset($reason)) {
        echo "\n\n";
    } else {
        // add stuff to make word red, etc.
        if($reason == "alldone") {
            echo "

    The spell checker has completed.
    Please close this window.

    ";
        } else {
            $workingtext=str_replace("\'","'",urldecode($workingtext));
            $workingtext=str_replace("\\\"","\"",$workingtext);
            $workingtext=str_replace("\\\\","\\",$workingtext);
            $workingtext=substr_replace ( $workingtext, "", $redend, 0);
            $workingtext=substr_replace ( $workingtext, "", $redstart, 0);
            $workingtext=str_replace ( "&", "&amp;", $workingtext);
            $workingtext=str_replace ( ">", "&gt;", $workingtext);
            $workingtext=str_replace ( "<", "&lt;", $workingtext);
            $workingtext=str_replace ( "\n", "
    ", $workingtext);
            $workingtext=str_replace ( " ", "&nbsp;", $workingtext);
            $workingtext=str_replace ( "&lt;a&nbsp;name=\"theword\"&gt;&lt;/a&gt;&lt;span&nbsp;style=\"color&nbsp;:&nbsp;red;\"&gt;", "", $workingtext);
            $workingtext=str_replace ( "&lt;/span&gt;", "
    ", $workingtext);
            echo $workingtext;
        }
    }
    ?>


    And spellcheckwindow.php... is long....



    sPHPell - Spell Checker





    if(isset($OrigionalText)) {
        // let's start to check the next word
        if (isset($CurrentWordStart) && $CurrentWordStart == "0" && isset($CurrentWordEnd) && $CurrentWordEnd == "0") {
            $thestartpos=0;
            $OrigionalText=str_replace("\\'","'",$OrigionalText);
            $WorkingText=str_replace("\\'","'",$WorkingText);
            $OrigionalText=str_replace("\\\"","\"",$OrigionalText);
            $WorkingText=str_replace("\\\"","\"",$WorkingText);
            $OrigionalText=str_replace("\\\\","\\",$OrigionalText);
            $WorkingText=str_replace("\\\\","\\",$WorkingText);
        } else {
            $thestartpos=$CurrentWordEnd;
            $OrigionalText=urldecode($OrigionalText);
            $WorkingText=urldecode($WorkingText);
            $IgnoreList=urldecode($IgnoreList);
            $OrigionalText=str_replace("\\'","'",$OrigionalText);
            $WorkingText=str_replace("\\'","'",$WorkingText);
            $OrigionalText=str_replace("\\\"","\"",$OrigionalText);
            $WorkingText=str_replace("\\\"","\"",$WorkingText);
            $OrigionalText=str_replace("\\\\","\\",$OrigionalText);
            $WorkingText=str_replace("\\\\","\\",$WorkingText);
        }
        
        // do requested functions here if need be
        switch ($spellaction) {
            case "change" :
                $changinglength=$CurrentWordEnd-$CurrentWordStart;
                $WorkingText=substr_replace($WorkingText,$ChangeToWord, $CurrentWordStart, $changinglength);
                $WorkingText=str_replace("\\'","'",$WorkingText);
                $WorkingText=str_replace("\\\"","\"",$WorkingText);
                $WorkingText=str_replace("\\\\","\\",$WorkingText);
                $CurrentWordEnd=strlen($ChangeToWord)+$CurrentWordStart;
                
                // let's go back and check it again
                $thestartpos=$CurrentWordStart;
            break;
            
            case "changeall" :
                $strbeforestart=substr($WorkingText,0,$CurrentWordStart);
                $findwordoffset=strlen($CurrentFormWord)-strlen($ChangeToWord);
                
                $numberofchangesbefore=substr_count($strbeforestart,$CurrentFormWord);
                
                $strbeforestart=str_replace($CurrentFormWord,$ChangeToWord,$strbeforestart);
                
                $CurrentWordStart=($findwordoffset * $numberofchangesbefore) + $CurrentWordStart;
                
                $strafterend=substr($WorkingText,$CurrentWordEnd);
                $strafterend=str_replace($CurrentFormWord,$ChangeToWord,$strafterend);
                
                $WorkingText=$strbeforestart.$ChangeToWord.$strafterend;
                
                // let's go back and check it again
                $thestartpos=$CurrentWordStart;
            break;
            
            case "ignore" :
                // do nothing, continue
            break;
            
            case "ignoreall" :
                // have ignore list checked below with each mispelling
                $IgnoreList=$IgnoreList.",".$ChangeToWord.",";
            break;
            
            case "closewindow" :
                echo "";
                flush();
                exit;
            break;
            
            case "cancel" :
                $sendbacktext=str_replace("\\","\\\\",$OrigionalText);
                $sendbacktext=str_replace("/","\\/",$sendbacktext);
                $sendbacktext=str_replace("'","\\'",$sendbacktext);
                $sendbacktext=str_replace("\"","\\\"",$sendbacktext);
                $sendbacktext=str_replace("\n","\\r",$sendbacktext);
                $sendbacktext=str_replace("\r","",$sendbacktext);
                echo "";
                echo "";
                flush();
                exit;
            break;
        }
        
        $sendbacktext=str_replace("\\","\\\\",$WorkingText);
        $sendbacktext=str_replace("/","\\/",$sendbacktext);
        $sendbacktext=str_replace("\\\\'","\\'",$sendbacktext);
        $sendbacktext=str_replace("'","\\'",$sendbacktext);
        $sendbacktext=str_replace("\"","\\\"",$sendbacktext);
        $sendbacktext=str_replace("\n","\\r",$sendbacktext);
        $sendbacktext=str_replace("\r","",$sendbacktext);
        echo "";
        
        $texttocheck=substr($WorkingText,$thestartpos);
        $texttocheck=str_replace("~","~~SPLSPACE~~",$texttocheck);
        $texttocheck=str_replace("' ","~~SPLSPACE~~~~SPLSPACE~~",$texttocheck);
        $texttocheck=str_replace(" '","~~SPLSPACE~~~~SPLSPACE~~",$texttocheck);
        $texttocheck=str_replace(" ","~~SPLSPACE~~",$texttocheck);
        $texttocheck=str_replace(",","~~SPLSPACE~~",$texttocheck);
        $texttocheck=str_replace("\n","~~SPLSPACE~~",$texttocheck);
        $texttocheck=str_replace("\r","~~SPLSPACE~~",$texttocheck);
        $stringofchars="`,!,@,#,$,%,^,&,*,(,),_,-,+,=,[,],{,},|,\",:,;,?,/,\\,>,.,<,1,2,3,4,5,6,7,8,9,0";
        $chararray=explode(",",$stringofchars);
        $chararraymax=count($chararray);
        $chararraycount=0;
        while ($chararraycount < $chararraymax) {
            $texttocheck=str_replace($chararray[$chararraycount],"~~SPLSPACE~~",$texttocheck);
            $chararraycount++;
        }
        
        // break into final word check array
        $textcheckarray=explode("~~SPLSPACE~~",$texttocheck);
        $textcheckarraymax=count($textcheckarray);
        $textcheckarraycounter=0;
        
        $pspell_link = pspell_new ($SpellLanguage, $SpellSpelling);
        $getsuggestions="";
        
        $misspellfound="no";
        while($textcheckarraycounter < $textcheckarraymax && $misspellfound == "no") {
            // let's check each word now.
            $thecurrentword=$textcheckarray[$textcheckarraycounter];
            
            if($thecurrentword != "") {
                if(!pspell_check($pspell_link, $thecurrentword) && !strpos("...".$IgnoreList,",".$thecurrentword.",")) {
                    $CurrentWordStart=strpos($WorkingText,$thecurrentword,$thestartpos);
                    $CurrentWordEnd=strlen($thecurrentword)+$CurrentWordStart;
                    $getsuggestions=pspell_suggest($pspell_link, $thecurrentword);
                    // echo $CurrentWordStart.$CurrentWordEnd;
                    $misspellfound="yes";
                }
            }
            
            $textcheckarraycounter++;
        }
        
        // if no misspells found, exit
        if($misspellfound == "no") {
            echo "";
            $alldone="yes";
        } else {
            echo "";
            $alldone="no";
        }
    }
    ?>
    $FormName="SpellCheckForm";
    $JavaText=" ";
    SPHPELLstartform($FormName,"spellcheckwindow.php");
    if(isset($OrigionalText) && $OrigionalText != "") {
        SPHPELLhidden("OrigionalText",urlencode($OrigionalText));
    } else {
        SPHPELLhidden("OrigionalText","");
    }
    if(isset($WorkingText) && $WorkingText != "") {
        SPHPELLhidden("WorkingText",urlencode($WorkingText));
    } else {
        SPHPELLhidden("WorkingText","");
    }
    if(isset($CurrentWordStart) && $CurrentWordStart != "") {
        SPHPELLhidden("CurrentWordStart",$CurrentWordStart);
    } else {
        SPHPELLhidden("CurrentWordStart","0");
    }
    if(isset($CurrentWordEnd) && $CurrentWordEnd != "") {
        SPHPELLhidden("CurrentWordEnd",$CurrentWordEnd);
    } else {
        SPHPELLhidden("CurrentWordEnd","0");
    }
    SPHPELLhidden("ReplaceWord","");
    if(isset($IgnoreList) && $IgnoreList != "") {
        SPHPELLhidden("IgnoreList",urlencode($IgnoreList));
    } else {
        SPHPELLhidden("IgnoreList","");
    }
    SPHPELLhidden("spellcheckfield",str_replace("\'","'",$spellcheckfield));
    SPHPELLhidden("CurrentFormWord",$thecurrentword);
    SPHPELLhidden("spellaction","");
    if($Browser == "Netscape") {
        $textboxwidth=12;
        $onepixwidth=183;
    } else {
        $textboxwidth=25;
        $onepixwidth=183;
    }
    ?>



       
           
           
       
       
       
       

            Change To:

    if($alldone == "yes") {
        SPHPELLtextbox($FormName,"ChangeToWord","Change To","","",$textboxwidth); 
    } else {
        SPHPELLtextbox($FormName,"ChangeToWord","Change To",$thecurrentword,"",$textboxwidth); 
    }
    ?>

           
           

            Suggestions:

           

           
           

    if($alldone == "no") {
        SPHPELLbutton("Change","onClick=\"document.SpellCheckForm.spellaction.value='change';document.SpellCheckForm.submit();\"");
        echo "&nbsp;";
        SPHPELLbutton("Change All","onClick=\"document.SpellCheckForm.spellaction.value='changeall';document.SpellCheckForm.submit();\"");
        echo "&nbsp;";
        SPHPELLbutton("Ignore","onClick=\"document.SpellCheckForm.spellaction.value='ignore';document.SpellCheckForm.submit();\"");
        echo "&nbsp;";
        SPHPELLbutton("Ignore All","onClick=\"document.SpellCheckForm.spellaction.value='ignoreall';document.SpellCheckForm.submit();\"");
        echo "
    \n";
        SPHPELLbutton("Finished (Keeps Changes)","onClick=\"top.self.close();\"");
        echo "&nbsp;";
        SPHPELLbutton("Cancel All Changes","onClick=\"document.SpellCheckForm.spellaction.value='cancel';document.SpellCheckForm.submit();\"");
    } else {
        SPHPELLbutton("Cancel All Changes","onClick=\"document.SpellCheckForm.spellaction.value='cancel';document.SpellCheckForm.submit();\"");
        echo "&nbsp;";
        SPHPELLbutton("Close Window (Keep Changes)","onClick=\"document.SpellCheckForm.spellaction.value='closewindow';document.SpellCheckForm.submit();\"");
    }
    ?>
       

    SPHPELLendform($FormName,$JavaText);
    if(!isset($OrigionalText)) {
        echo "\n\n";
    }
    ?>





    Thanks in advance!

    Source: http://community.livejournal.com/webdev/432693.html

    « Object Oriented Programming... || I've run out of ideas! »