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:
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:
And spellcheckwindow.php... is long....
Thanks in advance!
<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?spellcheckfiel d=<?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_r eplace("\'","'",urldecode($spellcheckfie ld))).");
</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("\'","'",urldec ode($workingtext));
$workingtext=str_replace("\\\"","\"",$wo rkingtext);
$workingtext=str_replace("\\\\","\\",$wo rkingtext);
$workingtext=substr_replace ( $workingtext, "</span>", $redend, 0);
$workingtext=substr_replace ( $workingtext, "<a name=\"theword\"></a><span style=\"color : red;\">", $redstart, 0);
$workingtext=str_replace ( "&", "&", $workingtext);
$workingtext=str_replace ( ">", ">", $workingtext);
$workingtext=str_replace ( "<", "<", $workingtext);
$workingtext=str_replace ( "\n", "<br>", $workingtext);
$workingtext=str_replace ( " ", " ", $workingtext);
$workingtext=str_replace ( "<a name=\"theword\"></a&g t;<span style=\"color :&nbs p;red;\">", "<a name=\"theword\"></a><span style=\"color : red;\">", $workingtext);
$workingtext=str_replace ( "</span>", "</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.val ue = document.SpellCheckForm.SuggestionList.o ptions[document.SpellCheckForm.Suggestio nList.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("\\'","'",$Or igionalText);
$WorkingText=str_replace("\\'","'",$Work ingText);
$OrigionalText=str_replace("\\\"","\"",$O rigionalText);
$WorkingText=str_replace("\\\"","\"",$Wo rkingText);
$OrigionalText=str_replace("\\\\","\\",$O rigionalText);
$WorkingText=str_replace("\\\\","\\",$Wo rkingText);
} else {
$thestartpos=$CurrentWordEnd;
$OrigionalText=urldecode($OrigionalText) ;
$WorkingText=urldecode($WorkingText);
$IgnoreList=urldecode($IgnoreList);
$OrigionalText=str_replace("\\'","'",$Or igionalText);
$WorkingText=str_replace("\\'","'",$Work ingText);
$OrigionalText=str_replace("\\\"","\"",$O rigionalText);
$WorkingText=str_replace("\\\"","\"",$Wo rkingText);
$OrigionalText=str_replace("\\\\","\\",$O rigionalText);
$WorkingText=str_replace("\\\\","\\",$Wo rkingText);
}
// do requested functions here if need be
switch ($spellaction) {
case "change" :
$changinglength=$CurrentWordEnd-$Current WordStart;
$WorkingText=substr_replace($WorkingText, $ChangeToWord, $CurrentWordStart, $changinglength);
$WorkingText=str_replace("\\'","'",$Work ingText);
$WorkingText=str_replace("\\\"","\"",$Wo rkingText);
$WorkingText=str_replace("\\\\","\\",$Wo rkingText);
$CurrentWordEnd=strlen($ChangeToWord)+$C urrentWordStart;
// let's go back and check it again
$thestartpos=$CurrentWordStart;
break;
case "changeall" :
$strbeforestart=substr($WorkingText,0,$C urrentWordStart);
$findwordoffset=strlen($CurrentFormWord) -strlen($ChangeToWord);
$numberofchangesbefore=substr_count($str beforestart,$CurrentFormWord);
$strbeforestart=str_replace($CurrentForm Word,$ChangeToWord,$strbeforestart);
$CurrentWordStart=($findwordoffset * $numberofchangesbefore) + $CurrentWordStart;
$strafterend=substr($WorkingText,$Curren tWordEnd);
$strafterend=str_replace($CurrentFormWor d,$ChangeToWord,$strafterend);
$WorkingText=$strbeforestart.$ChangeToWo rd.$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.",".$ChangeToWor d.",";
break;
case "closewindow" :
echo "<script language=\"JavaScript\">top.close();</sc ript>";
flush();
exit;
break;
case "cancel" :
$sendbacktext=str_replace("\\","\\\\",$O rigionalText);
$sendbacktext=str_replace("/","\\/",$sen dbacktext);
$sendbacktext=str_replace("'","\\'",$sen dbacktext);
$sendbacktext=str_replace("\"","\\\"",$s endbacktext);
$sendbacktext=str_replace("\n","\\r",$se ndbacktext);
$sendbacktext=str_replace("\r","",$sendb acktext);
echo "<script language=\"JavaScript\">".str_replace("\ '","'",$spellcheckfield).".value=\"".$se ndbacktext."\";</script>";
echo "<script language=\"JavaScript\">top.close();</sc ript>";
flush();
exit;
break;
}
$sendbacktext=str_replace("\\","\\\\",$W orkingText);
$sendbacktext=str_replace("/","\\/",$sen dbacktext);
$sendbacktext=str_replace("\\\\'","\\'", $sendbacktext);
$sendbacktext=str_replace("'","\\'",$sen dbacktext);
$sendbacktext=str_replace("\"","\\\"",$s endbacktext);
$sendbacktext=str_replace("\n","\\r",$se ndbacktext);
$sendbacktext=str_replace("\r","",$sendb acktext);
echo "<script language=\"JavaScript\">".str_replace("\ '","'",$spellcheckfield).".value='".$sen dbacktext."';</script>";
$texttocheck=substr($WorkingText,$thesta rtpos);
$texttocheck=str_replace("~","~~SPLSPACE~ ~",$texttocheck);
$texttocheck=str_replace("' ","~~SPLSPACE~~~~SPLSPACE~~",$texttochec k);
$texttocheck=str_replace(" '","~~SPLSPACE~~~~SPLSPACE~~",$texttoche ck);
$texttocheck=str_replace(" ","~~SPLSPACE~~",$texttocheck);
$texttocheck=str_replace(",","~~SPLSPACE~ ~",$texttocheck);
$texttocheck=str_replace("\n","~~SPLSPAC E~~",$texttocheck);
$texttocheck=str_replace("\r","~~SPLSPAC E~~",$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[$cha rarraycount],"~~SPLSPACE~~",$texttocheck) ;
$chararraycount++;
}
// break into final word check array
$textcheckarray=explode("~~SPLSPACE~~",$t exttocheck);
$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[$textche ckarraycounter];
if($thecurrentword != "") {
if(!pspell_check($pspell_link, $thecurrentword) && !strpos("...".$IgnoreList,",".$thecurren tword.",")) {
$CurrentWordStart=strpos($WorkingText,$t hecurrentword,$thestartpos);
$CurrentWordEnd=strlen($thecurrentword)+ $CurrentWordStart;
$getsuggestions=pspell_suggest($pspell_l ink, $thecurrentword);
// echo $CurrentWordStart.$CurrentWordEnd;
$misspellfound="yes";
}
}
$textcheckarraycounter++;
}
// if no misspells found, exit
if($misspellfound == "no") {
echo "<script language=\"JavaScript\">top.frames['spel ltext'].location='spellchecktext.php?spe llcheckfield=".str_replace("\'","'",urle ncode($spellcheckfield))."&reason=alldon e';</script>";
$alldone="yes";
} else {
echo "<script language=\"JavaScript\">top.frames['spel ltext'].location='spellchecktext.php?spe llcheckfield=".str_replace("\'","'",urle ncode($spellcheckfield))."&workingtext=" .urlencode($WorkingText)."&redstart=$Cur rentWordStart&redend=$CurrentWordEnd&rea son=stillgoing#theword';</script>";
$alldone="no";
}
}
?>
<?php
$FormName="SpellCheckForm";
$JavaText=" ";
SPHPELLstartform($FormName,"spellcheckwi ndow.php");
if(isset($OrigionalText) && $OrigionalText != "") {
SPHPELLhidden("OrigionalText",urlencode( $OrigionalText));
} else {
SPHPELLhidden("OrigionalText","");
}
if(isset($WorkingText) && $WorkingText != "") {
SPHPELLhidden("WorkingText",urlencode($W orkingText));
} else {
SPHPELLhidden("WorkingText","");
}
if(isset($CurrentWordStart) && $CurrentWordStart != "") {
SPHPELLhidden("CurrentWordStart",$Curren tWordStart);
} else {
SPHPELLhidden("CurrentWordStart","0");
}
if(isset($CurrentWordEnd) && $CurrentWordEnd != "") {
SPHPELLhidden("CurrentWordEnd",$CurrentW ordEnd);
} else {
SPHPELLhidden("CurrentWordEnd","0");
}
SPHPELLhidden("ReplaceWord","");
if(isset($IgnoreList) && $IgnoreList != "") {
SPHPELLhidden("IgnoreList",urlencode($Ig noreList));
} else {
SPHPELLhidden("IgnoreList","");
}
SPHPELLhidden("spellcheckfield",str_repl ace("\'","'",$spellcheckfield));
SPHPELLhidden("CurrentFormWord",$thecurr entword);
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[$getsuggestion scounter]."\">".$getsuggestions[$getsugg estionscounter]."\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=\"docume nt.SpellCheckForm.spellaction.value='cha nge';document.SpellCheckForm.submit();\" ");
echo " ";
SPHPELLbutton("Change All","onClick=\"document.SpellCheckForm.s pellaction.value='changeall';document.Sp ellCheckForm.submit();\"");
echo " ";
SPHPELLbutton("Ignore","onClick=\"docume nt.SpellCheckForm.spellaction.value='ign ore';document.SpellCheckForm.submit();\" ");
echo " ";
SPHPELLbutton("Ignore All","onClick=\"document.SpellCheckForm.s pellaction.value='ignoreall';document.Sp ellCheckForm.submit();\"");
echo "<br>\n";
SPHPELLbutton("Finished (Keeps Changes)","onClick=\"top.self.close();\" ");
echo " ";
SPHPELLbutton("Cancel All Changes","onClick=\"document.SpellCheckF orm.spellaction.value='cancel';document.S pellCheckForm.submit();\"");
} else {
SPHPELLbutton("Cancel All Changes","onClick=\"document.SpellCheckF orm.spellaction.value='cancel';document.S pellCheckForm.submit();\"");
echo " ";
SPHPELLbutton("Close Window (Keep Changes)","onClick=\"document.SpellCheck Form.spellaction.value='closewindow';doc ument.SpellCheckForm.submit();\"");
}
?>
</td>
</tr>
</table>
<?php
SPHPELLendform($FormName,$JavaText);
if(!isset($OrigionalText)) {
echo "\n<script language=\"JavaScript1.2\">
function loadOrigText(aTextField) {
document.SpellCheckForm.OrigionalText.va lue = aTextField.value;
document.SpellCheckForm.WorkingText.valu e = aTextField.value;
}
loadOrigText(".str_replace("\\","",str_r eplace("\'","'",$spellcheckfield)).");
document.SpellCheckForm.submit();
</script>\n";
}
?>
</body>
</html>Thanks in advance!
