Hi there,
I'm trying to institute remote scripting using an iframe and everything seems to be working great with the exception of JavaScript on the server side recognizing/parsing the embedded php within it. I'm really stumped on this error. This is my client.html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html><head><title>Remote Scripting with an IFrame - complexer client page</title>
<meta http-equiv="pragma" content="no-cache">
<script type="text/javascript">
function buildQueryString(theFormName) {
theForm = document.forms[theFormName];
var qs = ''
for (e=0;e<theForm.elements.length;e++) {
if (theForm.elements[e].name!='') {
qs+=(qs=='')?'?':'&'
qs+=theForm.elements[e].name+'='+escape(theForm.elements[e].value)
}
}
return qs
}
function messageReciept(name, msg) {
var theFormDiv = document.getElementById('theFormDiv');
theFormDiv.style.display = 'none';
var responseMessage = document.getElementById('responseMessage');
var message = '<p>Your message has been sent! Thank you.<\/p>'
message += ('<p>Your Name: <\/p>' + name)
message += ('<p>Your Message: <\/p>' + msg)
message += '<p><a href="#" onclick="showForm(); return false;">Send another message<\/a><\/p>'
responseMessage.innerHTML = message;
responseMessage.style.display = 'block';
}
var IFrameObj; // our IFrame object
function callToServer(theFormName) {
if (!document.createElement) {return true};
var IFrameDoc;
var URL = 'server.php' + buildQueryString(theFormName);
if (!IFrameObj && document.createElement) {
// create the IFrame and assign a reference to the
// object to our global variable IFrameObj.
// this will only happen the first time
// callToServer() is called
var tempIFrame=document.createElement('iframe');
tempIFrame.setAttribute('id','RSIFrame');
tempIFrame.style.border='0px';
tempIFrame.style.width='0px';
tempIFrame.style.height='0px';
IFrameObj = document.body.appendChild(tempIFrame);
if (document.frames) {
// this is for IE5 Mac, because it will only
// allow access to the document object
// of the IFrame if we access it through
// the document.frames array
IFrameObj = document.frames['RSIFrame'];
}
}
if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
// we have to give NS6 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer("'+theFormName+'")',10);
return false;
}
if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
// For IE5
IFrameDoc = IFrameObj.document;
} else {
return true;
}
IFrameDoc.location.replace(URL);
return false;
}
function showForm() {
var theFormDiv = document.getElementById('theFormDiv');
theFormDiv.style.display = 'block';
document.forms['emailForm'].reset();
var responseMessage = document.getElementById('responseMessage');
responseMessage.style.display = 'none';
}
function processState(st) {
alert(st)
}
</script>
</head>
<body>
<div id="responseMessage" style="display:none"></div>
<div id="theFormDiv">
<form name="emailForm" id="emailForm"
action="server.php"
onsubmit="return callToServer(this.name)">
Your name:
<input type="text" name="realname">
Your message:
<textarea name="message" cols="50" rows="10"></textarea>
<input type="submit" value="submit">
</form>
</div>
</body>
</html>
And this is what I've got for server.php:
<?php
$username = "testName";
?>
<script language="javascript" type="text/javascript">
parent.window.messageReciept('<?php =$username;?>' + 'ggg', '<?php echo "hhh";?>')
</script>
After entering some arbitrary values into the 'Your name' and 'Your message' box and submitting, this is the output I get:
Your message has been sent! Thank you.
Your Name:
ggg
Your Message:
Send another message
I currently have the xampp (LAMP) installation set up on my machine and it seems to parse php files/commands with no trouble. Any idea why I cannot get JavaScript to recognize/parse any php??
I'm really stumped, any help you can offer would be greatly appreciated, or even let me know if you're unable to reproduce the error on your machine, thanks!!!