PDA

View Full Version : Way to include PHP file into textarea from a link


RexxCrow
06-06-2008, 05:51 AM
I am trying to figure a way of putting a preformatted text form into a textarea after clicking on a link for it to be submitted as a post. I have it working as a JavaScript, though want to try and perform it from a PHP file instead:

from the overall header function...
function writeESDR(){
$writeinfo="form..."
document.getElementById('message').innerHTML=$writeinfo
}

The link from the post page template:
<span style="padding-left:150px;"><a href="javascript:void(0)" onClick="writeESDR()" target="_self" title="Click to write a Review."><img class="trans2ON" style="vertical-align:middle;" onmouseover="this.className='trans2OFF'" onmouseout="this.className='trans2ON'" src="{T_THEME_PATH}/images/wr.png" width="40" height="40" alt="Click to write a Review." /></a></span>


Is there a way to do it as or an inline method even? (I have tried using &gt; and &gt in place of < >, so far this tactic does not seem to work;):

document.getElementById('message').innerHTML="<?php include('formfile.PHP'); ?>"


Also it seems IE stripes out the conditional tags (or whatever they are called), \t \n, is there a way around this? Firefox keeps them in there though.

tomws
06-06-2008, 03:37 PM
Not sure I understand exactly what you're doing, but I tried this and got file contents into a text area including IE conditionals.
<textarea cols="80" rows="24">
<?php
$str=htmlentities(file_get_contents('mytest.php'));
echo $str;
?>
</textarea>

RexxCrow
06-10-2008, 01:11 AM
OK, I have tried several different methods and nothing seems to want to work at all, this is suppose to work but it also is not working, I am not even able to get an alert to come up at the start of the function and I am not getting any error messages either, anybody have any ideas on how to do this? To clarify what I need to accomplish is to display a text file with all CR's and tabs as formatted in the file within a text box as a template to be filled out and posted.

Currently I am using an entire URL for my variable to pass, could that be causing the issue? I am doing that because I do not know what the actual directory the forum is within when making posts.


function wF(url){

var req = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest && !(window.ActiveXObject)){
try{req = new XMLHttpRequest()}
catch(e) { req = false }
}else // branch for IE/Windows ActiveX version{
if(window.ActiveXObject){
try { req = new ActiveXObject("Msxml2.XMLHTTP") }
catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP") }
catch(e) { req = false }
}
}
}
if(req){
req.open("GET", url, false);
req.send("");
return req.responseText
}
return ''
document.getElementById('message').innerHTML=req
}

This is accessed by an onclick event within a link:
onClick="wF('http://..../ESDR.txt')"

tomws
06-10-2008, 01:25 PM
Try these changes.


function wF(url){

var req = false;
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest && !(window.ActiveXObject)){
try{req = new XMLHttpRequest()}
catch(e) { req = false }
}else // branch for IE/Windows ActiveX version{
if(window.ActiveXObject){
try { req = new ActiveXObject("Msxml2.XMLHTTP") }
catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP") }
catch(e) { req = false }
}
}
}
if(req){
req.open("GET", url, false);
req.send("");
/*return req.responseText*/
req.onreadystatechange=function()
{
if (req.readyState == 4)
{
return req.responseText;
}
}
}
return ''
document.getElementById('message').innerHTML=req
}

Also, the bottom two lines must be out of order. It doesn't make sense to try to set an innerHTML after the function has returned.

RexxCrow
06-10-2008, 10:07 PM
It appears to be that code is just written badly, I found this and it works, except that IE is still stripping out all of the whitespace into a solid block of text, is there a way around this, a maybe a way to XHTML tags and CSS except convert them into their purpose rather then displaying them within the textarea?


function wF(url){
if (window.XMLHttpRequest) { // code for Mozilla, Safari, ** And Now IE 7 **, etc
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) { //IE
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
}
if (typeof(xmlhttp)=='object') {
xmlhttp.onreadystatechange=postFileReady;
xmlhttp.open('GET', url, true);
xmlhttp.send(null);
}
}

// function to handle asynchronous call
function postFileReady() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) {
document.getElementById('message').innerHTML=xmlhttp.responseText;
}
}
}

logictrap
06-10-2008, 11:29 PM
HTML doesn't recognize tabs so you'll probably need to use either a table or divs as a replacement.

HTML also ignores multiple space characters but you can get multiple spaces using &nbsp;

RexxCrow
06-10-2008, 11:45 PM
This seems to work except it is still ignoring JavaScript Escapes. though it is acknowledging spaces that I put into the file manually. This problem is only occurring IE, Firefox treats the Escapes within Textboxes.

function wF(url){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
}
if(typeof(xmlhttp)=='object'){
xmlhttp.onreadystatechange=postFileReady;
xmlhttp.open('GET', url, true);
xmlhttp.send(null);
}
}
// function to handle asynchronous call
function postFileReady(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
$prep=xmlhttp.responseText;
$prep=document.createTextNode($prep)
setp=document.getElementById("message");
setp.appendChild($prep);
}
}
}

RexxCrow
06-10-2008, 11:53 PM
HTML doesn't recognize tabs so you'll probably need to use either a table or divs as a replacement.

HTML also ignores multiple space characters but you can get multiple spaces using &nbsp;

To bad there is not code for CR or LF.

logictrap
06-11-2008, 12:05 AM
You can replace crlf with <br/>

RexxCrow
06-12-2008, 09:33 PM
I tried that a few different ways and it does not seem to want to do anything, it just shows up as text.

logictrap
06-12-2008, 11:55 PM
Use the 'view source' option in your browser to see if the output is actual html and not htmlentities.