Jump to content

Recommended Posts

I am trying to install the rich text editor in my userarea so I can edit pages on my website.

I have already got the functionality working which is in a file called EditPages.rqd but, only using a text box,

I tryed putting the rich text editor in the place of the text box, but when display in my browser and I select a file to edit using my drop down menu, it does not show the rich text editor only the Save File button. where as if I just have a text box there it works great.

 

Heres is what on my pages2.html (With the Rich text editor)page:

<?php
require_once ("EditPage.rqd");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Page Editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="styles/styles.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="richtext_compressed.js"></script>

</head>
<body>
<?php include ('structure/head.inc');?>
  <div class="clear"> </div>
  <div id="sidebar"> <?php include ('structure/menu.inc');?>
  </div>
  
  
<div id="content">
<h3>Edit Pages</h3>
    <br />

<form name="myform" action="pages2.html" method="post" onsubmit="return submitForm();">

<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
updateRTE('$filename'); //use this when syncing only 1 rich text editor ("rtel" is name of editor)
//updateRTEs(); //uncomment and call this line instead if there are multiple rich text editors inside the form
alert("Submitted value: "+document.myform.$file.$filename.) //alert submitted value
return true; //Set to false to disable form submission, for easy debugging.
}

//Usage: initRTE(imagesPath, includesPath, cssFile)
initRTE("images/", "", "");
//-->
</script>
    <label for="file">Choose which page content to edit:</label> 
        <select name="file" id="file">
            <optgroup label="Pages to Edit">
                <option value="home"<?php select('home'); ?>>Home</option>
                <option value="general"<?php select('general'); ?>>General - Club Info</option>
                <option value="kit"<?php select('kit'); ?>>Kit</option>
			<option value="training"<?php select('training'); ?>>Training</option>
			<option value="coaching"<?php select('coaching'); ?>>Coaching</option>
			<option value="fees"<?php select('fees'); ?>>Fees</option>
			<option value="pitches"<?php select('pitches'); ?>>Pitches</option>
			<option value="social"<?php select('social'); ?>>Social</option>
			<option value="latest"<?php select('latest'); ?>>Latest News</option>
            </optgroup>
        </select> 
    <input type="submit" name="load" value="Load File" />
    <hr />
    <?echo $Message?>
    <?php

if(isset($file) && !empty($file))
{
    echo '<script language="JavaScript" type="text/javascript">

writeRichText("'.$filename.'", "'.$file.'", 400, 200, true, false); 

</script><br>
<input type="submit" name="save" value="Save File" />';
}
else
{
    echo '<strong>Please choose a file to edit from the dropdown list above.</strong>';
}

?>
</form>

</div>
  <div class="clear"> </div>
   
</div>
</body>
</html>

 

Here is whats on my EditPages.rqd

 

<?php
function stripstring($string) {
    if(get_magic_quotes_gpc()) {
        return stripslashes($string);
    } else {
        return $string;
    }
}

$files = array(
/** Drop-Down Value => File Path **/
    'home' => './text/home.txt',
    'general' => './text/general.txt',
'joining' => './text/joining.txt',
'kit' => './text/kit.txt',
'news' => './text/news.txt',
        'fees' => './text/fees.txt',
'pitches' => './text/pitches.txt',
'training' => './text/training.txt',
'coaching' => './text/coaching.txt',
    'social' => './text/social.txt',
'latest' => './text/latest.txt'
);

if($_SERVER['REQUEST_METHOD'] == "POST")
{
    if(isset($_POST['load']))
    {
        if(!empty($_POST['file']) && array_key_exists($_POST['file'],$files))
        {
            $file = file_get_contents($files[$_POST['file']]);
            $filename = $_POST['file'];
        }
    }
    elseif(isset($_POST['save']))
    {
        if(!empty($_POST['filecontents']) && array_key_exists($_POST['filename'],$files))
        {
            $filecontents = stripstring($_POST['filecontents']);
            if(phpversion() > '5.0.0')
            {
                if(!file_put_contents($files[$_POST['filename']],$filecontents))
                {
                    $Message = "<a href=\"#\">Error writing to file</a><br>";
                }
                else
                {
                     $Message = "<a href=\"#\">Saved to file successfully</a><br>";
                }
            }
            else
            {
                $fhandle = fopen($files[$_POST['filename']],'w');
                if(fwrite($fhandle,$filecontents) == false)
                {
                    $Message = "<a href=\"#\">Oops! There was an Error writing to file: contact chantal@pglc.co.uk</a><br>";
                }
                else
                {
                    fclose($fhandle);
                   $Message = "<a href=\"#\">File Update successfully</a><br>";
                }
            }
        }
    }
}

function select($file)
{
    global $filename;
    
    if($filename == $file)
    {
        echo ' selected="selected"';
    }
}

?>

 

 

Here is the WORKING script with the use of just the text box on pages2.html:

 

<?php
require_once ("EditPage.rqd");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Page Editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="styles/styles.css" rel="stylesheet" type="text/css" />


</head>
<body>
<?php include ('structure/head.inc');?>
  <div class="clear"> </div>
  <div id="sidebar"> <?php include ('structure/menu.inc');?>
  </div>
  
  
<div id="content">
<h3>Edit Pages</h3>
    <br />
<form action="pages2.html" method="post">
    <label for="file">Choose which page content to edit:</label> 
        <select name="file" id="file">
            <optgroup label="Pages to Edit">
                <option value="home"<?php select('home'); ?>>Home</option>
                <option value="general"<?php select('general'); ?>>General - Club Info</option>
                <option value="kit"<?php select('kit'); ?>>Kit</option>
			<option value="training"<?php select('training'); ?>>Training</option>
			<option value="coaching"<?php select('coaching'); ?>>Coaching</option>
			<option value="fees"<?php select('fees'); ?>>Fees</option>
			<option value="pitches"<?php select('pitches'); ?>>Pitches</option>
			<option value="social"<?php select('social'); ?>>Social</option>
			<option value="latest"<?php select('latest'); ?>>Latest News</option>
            </optgroup>
        </select> 
    <input type="submit" name="load" value="Load File" />
    <hr />
    <?echo $Message?>
    <?php

if(isset($file) && !empty($file))
{
    echo '<textarea name="filecontents" id="filecontents" cols="60" rows="20">'.$file.'</textarea>
<input type="hidden" name="filename" value="'.$filename.'" /><br /><input type="submit" name="save" value="Save File" />';
}
else
{
    echo '<strong>Please choose a file to edit from the dropdown list above.</strong>';
}

?>
</form>
      

</div>
  <div class="clear"> </div>
  
  
  

  
</div>
</body>
</html>


Link to comment
https://forums.phpfreaks.com/topic/166120-rich-text-editor-please-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.