Image

Image_elioclya_ wrote in Imagewebdev

The horrors of frames

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:

<frameset rows="*,*" scrolling="auto" border="0">
<frame name="spelltext" src="spellchecktext.php?spellcheckfield=<?php echo
str_replace("\\","",str_replace("\'","'",$spellcheckfield)); ?>" marginwidth="0" marginheight="0"
scrolling="auto" frameborder="0" border="0">
<frame name="spellcontrols" src="spellcheckwindow.php?spellcheckfield=<?php echo
str_replace("\\","",str_replace("\'","'",$spellcheckfield)); ?>" marginwidth="0" marginheight="0"
scrolling="auto" frameborder="0" border="0">
<noframes>
<h2>You must have frames enabled in your web browser to use the spell checker.</h2>
</noframes>
</frameset>


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:

<body bgcolor="White">
<font face="verdana">
<?php
if (!isset($reason)) {
    echo "\n<script language=\"JavaScript1.2\">
function loadOrigText(aTextField) {
    document.write(aTextField.value);
}
loadOrigText(".str_replace("\\","",str_replace("\'","'",urldecode($spellcheckfield))).");
</script>\n";
} else {
    // add stuff to make word red, etc.
    if($reason == "alldone") {
        echo "<div align=\"center\" style=\"color : #FF0000\"><h2>The spell checker has completed.<br>Please close this window.</h2></div>";
    } else {
        $workingtext=str_replace("\'","'",urldecode($workingtext));
        $workingtext=str_replace("\\\"","\"",$workingtext);
        $workingtext=str_replace("\\\\","\\",$workingtext);
        $workingtext=substr_replace ( $workingtext, "</span>", $redend, 0);
        $workingtext=substr_replace ( $workingtext, "<a name=\"theword\"></a><span style=\"color : red;\">", $redstart, 0);
        $workingtext=str_replace ( "&", "&amp;", $workingtext);
        $workingtext=str_replace ( ">", "&gt;", $workingtext);
        $workingtext=str_replace ( "<", "&lt;", $workingtext);
        $workingtext=str_replace ( "\n", "<br>", $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;", "<a name=\"theword\"></a><span style=\"color : red;\">", $workingtext);
        $workingtext=str_replace ( "&lt;/span&gt;", "</span>", $workingtext);
        echo $workingtext;
    }
}
?>
</body>


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

<html>
<head>
<title>sPHPell - Spell Checker</title>
</head>
<script language="JavaScript1.2">
function UpdateChangeTo() {
    document.SpellCheckForm.ChangeToWord.value = document.SpellCheckForm.SuggestionList.options[document.SpellCheckForm.SuggestionList.selectedIndex].value;
}
</script>
</head>
<body onload="self.focus();" bgcolor="White">
<font face="verdana">
<?php
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 "<script language=\"JavaScript\">top.close();</script>";
            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 "<script language=\"JavaScript\">".str_replace("\'","'",$spellcheckfield).".value=\"".$sendbacktext."\";</script>";
            echo "<script language=\"JavaScript\">top.close();</script>";
            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 "<script language=\"JavaScript\">".str_replace("\'","'",$spellcheckfield).".value='".$sendbacktext."';</script>";
    
    $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 "<script language=\"JavaScript\">top.frames['spelltext'].location='spellchecktext.php?spellcheckfield=".str_replace("\'","'",urlencode($spellcheckfield))."&reason=alldone';</script>";
        $alldone="yes";
    } else {
        echo "<script language=\"JavaScript\">top.frames['spelltext'].location='spellchecktext.php?spellcheckfield=".str_replace("\'","'",urlencode($spellcheckfield))."&workingtext=".urlencode($WorkingText)."&redstart=$CurrentWordStart&redend=$CurrentWordEnd&reason=stillgoing#theword';</script>";
        $alldone="no";
    }
}
?>
<?php
$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;
}
?>
<table border="0">
<tr><td align="center">
<table border="0" bgcolor="#000099">
    <tr>
        <td align="left" valign="top"><font color="white">
        <b>Change To:</b><br>
<?php 
if($alldone == "yes") {
    SPHPELLtextbox($FormName,"ChangeToWord","Change To","","",$textboxwidth); 
} else {
    SPHPELLtextbox($FormName,"ChangeToWord","Change To",$thecurrentword,"",$textboxwidth); 
}
?><br>
        <img src="<?php echo $ApplicationImageDir; ?>reserved/onepixel.gif" width="<?php echo $textboxwidth; ?>" height="1" alt="" border="0">
        </td>
        <td align="left" valign="top"><font color="white">
        <b>Suggestions:</b><br>
        <select name="SuggestionList" size="5" onchange="UpdateChangeTo();">
            <?php
            if (!isset($getsuggestions) || count($getsuggestions) == 0 || $alldone == "yes") {
                echo "<option value=\"$thecurrentword\">[There are no suggestions]";
            } else {
                $getsuggestionsmax=count($getsuggestions);
                $getsuggestionscounter=0;
                
                while ($getsuggestionscounter < $getsuggestionsmax) {
                    echo "<option value=\"".$getsuggestions[$getsuggestionscounter]."\">".$getsuggestions[$getsuggestionscounter]."\n";
                    $getsuggestionscounter++;
                }
            }
            ?>
        </select><br>
        <img src="<?php echo $ApplicationImageDir; ?>reserved/onepixel.gif" width="183" height="1" alt="" border="0">
        </td>
    </tr>
    <tr>
    <td align="right" valign="top" colspan="2">
<?php
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 "<br>\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();\"");
}
?>
    </td>
    </tr>
</table>
<?php
SPHPELLendform($FormName,$JavaText);
if(!isset($OrigionalText)) {
    echo "\n<script language=\"JavaScript1.2\">
function loadOrigText(aTextField) {
    document.SpellCheckForm.OrigionalText.value = aTextField.value;
    document.SpellCheckForm.WorkingText.value = aTextField.value;
}
loadOrigText(".str_replace("\\","",str_replace("\'","'",$spellcheckfield)).");
document.SpellCheckForm.submit();
</script>\n";
}
?>
</body>
</html>




Thanks in advance!