I have a problem with submitting a form to a PHP page through a
dynamically created IFRAME in IE7. This code works fine in Firefox.
However, IE7 submits an empty form--the correct PHP page is called, but
no form variables are passed to the page.
Here's the client-side code:
//Create or reuse an IFRAME to submit data to a specified page.
//commandToken: A string that tells the page what to do.
//data: Data that the page will work with.
//callbackFunctionName: Name of javascript function to call when the
page returns.
//userID: ID of user.
//url: Page to which form will be submitted.
//iFrame: Name or reference of IFRAME through which the form data will
be submitted.
GenericWindow.prototype.executeServerRequest2 = function(commandToken,
data, callbackFunctionName, userID, url, iFrame)
{
var theIFRAME = null;
//If the specified IFRAME is a string then create the new IFRAME
element.
if(iFrame.length)
{
theIFRAME = this.createDataExchangeIFrame2(iFrame);
}
else
{
theIFRAME = iFrame;
}
if(callbackFunctionName != null)
{
if(!url)
{
url = serverURL;
}
else
{
url = serverURLBase + url;
}
var htmlString = "<html><body onLoad=''>";
htmlString += '<form action="' + url + '" id="submitForm"
name="submitForm" method="post">';
htmlString +='<input type="hidden" id="USERID" name="USERID" value="'
+ userID + '">';
htmlString +='<input type="hidden" id="DATA" name="DATA" value="' +
data + '">';
htmlString +='<input type="hidden" id="COMMAND" name="COMMAND"
value="' + commandToken + '">';
htmlString +='<input type="hidden" id="CALLBACK" name="CALLBACK"
value="window.parent.bbsRenderer.getWindow("' + this._windowName +
'").' + callbackFunctionName + '()">';
htmlString +='<input type="hidden" id="AUTHENTICATION_TOKEN"
name="AUTHENTICATION_TOKEN" value="' +
document.getElementById("AUTHORIZATION_TOKEN").value + '">';
htmlString +='</form>';
htmlString +='</body></html>';
this.logCommand(commandToken, htmlString);
if(theIFRAME.contentDocument)
{
//For Mozilla and similar browsers.
theIFRAME.contentDocument.write(htmlString);
theIFRAME.contentDocument.getElementById("submitForm").submit();
}
else if(theIFRAME.document)
{
//For IE and similar browsers.
document.frames[theIFRAME.id].document.write(htmlString);
document.frames[theIFRAME.id].document.forms[0].submit();
}
}
return theIFRAME;
}
/*Creates the IFRAME used to communicate between the window and the
server.
If the IFRAME already exists, then it will be reused.*/
GenericWindow.prototype.createDataExchangeIFrame2 = function(iFrameID)
{
var iFrame = document.getElementById(iFrameID);
if(iFrame != null)
{
return iFrame;
}
else
{
iFrame = document.createElement("IFRAME");
if(iFrameID == null)
{
iFrame.id = this._windowName + "_DataExchangeIFrame_" +
this._dataExchangeIFrameList.length;
}
else
{
iFrame.id = iFrameID;
}
this._windowFrame.appendChild(iFrame);
this._dataExchangeIFrameList[this._dataExchangeIFrameList.length] =
iFrame;
iFrame.src = "blank.html";
return iFrame;
}
}
Here's the server-side code:
$userID = $_POST['USERID']; //Calling process's user ID. The value
must be numeric and not null.
$data = $_POST['DATA']; //Calling process's data.
$callback = $_POST['CALLBACK']; //Calling process's callback
information.
$commandToken = $_POST['COMMAND']; //Calling process's command token.
This value is required.
$authenticationToken = $_POST['AUTHENTICATION_TOKEN']; //Calling
process's authentication token, used to verify sessions.
Result of a call in Firefox (I used PHPINFO() to dump the request and
post variables):
_REQUEST["USERID"] null
_REQUEST["DATA"] <GET_ROOM_DESCRIPTION roomID=\'2\' userID=\'0\'/>
_REQUEST["COMMAND"] GET_ROOM_DESCRIPTION
_REQUEST["CALLBACK"] window.parent.bbsRenderer.getWindow(\"LoginWindow\").handleGetDataResponse()
_REQUEST["AUTHENTICATION_TOKEN"] no value
_POST["USERID"] null
_POST["DATA"] <GET_ROOM_DESCRIPTION roomID=\'2\' userID=\'0\'/>
_POST["COMMAND"] GET_ROOM_DESCRIPTION
_POST["CALLBACK"] window.parent.bbsRenderer.getWindow(\"LoginWindow\").handleGetDataResponse()
_POST["AUTHENTICATION_TOKEN"] no value
The same call with the same data values produces no request or post
variables from IE.
Any help would be appreciated!
gzannd - 30 Dec 2006 20:54 GMT
I rebooted the computer, and the problem seems to have gone away...
> I have a problem with submitting a form to a PHP page through a
> dynamically created IFRAME in IE7. This code works fine in Firefox.
[quoted text clipped - 135 lines]
>
> Any help would be appreciated!