Current location: Hot Scripts Forums » Programming Languages » PHP » populate textarea using dropdown list


populate textarea using dropdown list

Reply
  #1 (permalink)  
Old 12-14-09, 12:31 PM
beazleybub beazleybub is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
populate textarea using dropdown list

Hello,

I have a text area that displays the contents of an external source file for editing using tinymce.
I would like to have a dropdown list so I can select other external sources to load into the textarea for editing.
How can I accomplish this?

I'm not asking for someone to do this for me but rather to help me into the right direction.
"Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life"

Thanks

editor.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>editor</title>
<!-- TinyMCE -->
<!--<script src="jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script type="text/javascript">
    tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "ibrowser,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",
 
        // Theme options
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,|,image,ibrowser,|,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,ibrowser",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,
 
        // Example content CSS (should be your site CSS)
        content_css : "css/content.css",
 
        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",
 
        // Replace values for the template plugin
        template_replace_values : {
            username : "Some User",
            staffid : "991234"
        }
    });
</script>-->
<!-- /TinyMCE -->
</head>
 
<body>
 
 
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){ 
$data = $_POST['data'];
$file = "data.php"; 
 
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 
 
fclose($fp); 
echo "Saved to $file successfully!";
 
}
?><?php $myFile = "data.php";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
?>
<form action="editor.php?saving=1" method="post" name="formd">
    <textarea cols="100" name="data" rows="10">
<?php echo $theData;?>
</textarea> <br><input type="submit" value="Save">
</form>
<p><a href="data.php"><b>VIEW</b></a></p>
 
</body>
 
</html>
data.php
Code:
<p>This is the data to be sent to the text area</p>

Last edited by beazleybub; 12-14-09 at 12:34 PM. Reason: code tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-14-09, 02:17 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by beazleybub View Post
I have a text area that displays the contents of an external source file for editing using tinymce.
I would like to have a dropdown list so I can select other external sources to load into the textarea for editing. How can I accomplish this?
Probably the best place to ask a question like this is in the TinyMCE Support Forum, where it's probably been answered many, many times. Apparently you use one of the built-in commands:

HTML Code:
<script type="text/javascript">
    tinyMCE.get(mceId).execCommand('mceSetContent',false, '<p>some text<table></table></p>' );
</script>

Quote:
Originally Posted by beazleybub View Post
"Give a man a fish and he will eat for a day. Teach a man to fish and he will eat for the rest of his life"
"Teach a man to fish, and he will sit in the boat and drink beer all day."
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-14-09, 02:25 PM
beazleybub beazleybub is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Iv'e tried asking there

Thanks for your reply.

Iv'e tried asking questions there but can never get a straight forward answer from anyone there.

You always get "you need a cms like joomla".

I don't want joomla

I could do this if I could just pass a variable from the dropdown list but I don't know how.

I sorta have a grasp on this but am stuck.

Code:
<form name="myForm" method="post" action="passvariable.html">

<select name="DATA" size="1">
<option>file1</option>
<option>file2</option>
</select>
<?php $_POST['DATA'];//the value is stored here. ?>
<input type="submit" name="submit" value="submit!">
</form>
<?php echo $DATA; ?>
thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-14-09, 03:14 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
HTML Code:
<select name="source">
<option>file1</option>
<option>file2</option>
</select>
PHP Code:

/* Change $myFile = "data.php"; to ... */

$myFile $_POST['source'];
if (
is_file($myFile))
  
/* File is good, try to read it */
else
  
/* Use a default file or crash */ 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
beazleybub (12-14-09)
  #5 (permalink)  
Old 12-14-09, 03:37 PM
beazleybub beazleybub is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Making progress

wirehopper,

Thanks for helping!

It sorta works now but on initialization I get some errors.
Please check out my code.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>editor</title>
<!-- TinyMCE -->
<script src="jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "ibrowser,safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,|,image,ibrowser,|,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,ibrowser",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- /TinyMCE -->
</head>

<body>

<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){ 
$data = $_POST['data'];
$file = "data.php"; 

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
$theMessage = "Saved!";
}
?>

<?php
$myFile = $_POST['source']; 
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
?>

<div style="height:25px">
<?php echo $theMessage; ?>
</div>
<form name="myForm" method="post" action="editor.php">

<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" name="submit" value="submit!">
</form>

<form action="editor.php?saving=1" method="post" name="form">
	<textarea cols="100" name="data" rows="10">
<?php echo $theData;?>
</textarea> <br><input type="submit" value="Save">
</form>
<p><a href="data.php"><b>VIEW</b></a></p>

</body>

</html>
So close

Last edited by beazleybub; 12-14-09 at 03:52 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 12-14-09, 06:43 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
PHP Code:

if (isset($_POST['source']))

  
$myFile $_POST['source']; 
else
  
$myFile='default.file'
Please post the errors
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
beazleybub (12-15-09)
  #7 (permalink)  
Old 12-15-09, 02:43 AM
beazleybub beazleybub is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Thank you so much!

wirehopper,

Thank you so much for your help. It makes me feel good that there are still people in the world that are kind to others. You never had to help me out but you did.

I will take what you have shown me and try to apply it to when I have to save the file.
Right now when you click the save button it saves whatever is loaded into the textarea to data.php. I will need to be able to save whatever is in the textarea to the file that was opened in the textarea.

Cheers my friend.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 12-15-09, 03:31 AM
beazleybub beazleybub is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Wirehopper,

I was able to get the save function working based on your earlier example but I have made the script overly complicated.

Can you suggest a way for me to simplify it?

Thanks.
Attached Files
File Type: zip editor-php-2.zip (1.2 KB, 33 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 12-15-09, 07:13 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Please post the code that gets the data from $_POST and reads the file.

I'm sorry - I don't have time to download and review code in .zip files.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 12-15-09, 02:27 PM
beazleybub beazleybub is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
This is the current save function based on your example from the open function.
Code:
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){ 
$data = $_POST['data'];
if (isset($_POST['source'])) 
  $file = $_POST['source'];  
else 
  $file='instructions.php';

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
$theMessage = "Saved!";
}
?>
This is the form that I have to choose the file to save to.
Code:
<form action="editor.php?saving=1" method="post" name="form">
	<textarea cols="100" name="data" rows="10">
<?php echo $theData;?>
</textarea>
<br><br>
<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" value="Choose Where To Save">
</form>
What I meant by me making things overly complicated was I now have two dropdown boxes, one for opening and one for saving. I would like to simplify it to one dropdown box that opens the file and remembers what file is open so when I click save it simply saves to the file that I opened from the dropdown box.

Here is the complete code.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>editor</title>

</head>

<body>

<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){ 
$data = $_POST['data'];
if (isset($_POST['source'])) 
  $file = $_POST['source'];  
else 
  $file='instructions.php'; /* I will have to fix this to save to the file loaded somehow*/

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
$theMessage = "Saved!";
}
?>

<?php
if (isset($_POST['source'])) 
  $myFile = $_POST['source'];  
else 
  $myFile='instructions.php'; 
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
?>

<div style="height:25px">
<?php echo $theMessage; ?>
</div>
<form name="myForm" method="post" action="editor.php">

<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" name="submit" value="Choose File To Edit">

</form>

<form action="editor.php?saving=1" method="post" name="form">
	<textarea cols="100" name="data" rows="10">
<?php echo $theData;?>
</textarea>
<br><br>
<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" value="Choose Where To Save">
</form>

</body>

</html>
I thought using a zip file would be easy for you that's why I did it that way.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
refreshing dropdown list when selecting another drop down list theighost Script Requests 3 08-14-08 09:30 AM
refreshing dropdown list when selecting another drop down list theighost PHP 1 08-13-08 11:10 AM
Can I populate a dropdown list???? zorrox02 JavaScript 4 10-01-04 05:03 AM


All times are GMT -5. The time now is 06:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.