views:

243

answers:

3

I have this code.

The code below is working in Firefox, but it is not in IE

<?php // file: login_dfr.php ?>
<body>
<?php
$data = getLoginData($_SESSION['whoyouare']);
?>
    <form name="frm_redirect_dfr" action="<?php echo $data['url']; ?>" method="POST" id="frm_redirect_dfr" style="display: none;">
    <input name="DFRNet_User" value="<?php echo $data['username']; ?>" type="hidden" />
    <input name="DFRNet_Pass" value="<?php echo $data['password']; ?>" type="hidden" />
    <input name="tbllogin" value="login" type="hidden" />
    <input type="submit" value="submit" />
    </form>
    <script language="javascript" type="text/javascript">
    document.forms["frm_redirect_dfr"].submit();
    </script>
</body>

What I want to do is, when user access the page, it first will try to get login data, echo it in the form, and submit the form automatically using javascript

Update: I forget to mention that the code above is on a Frame, the mainFrame code is like below:

<?php session_start(); ?>
<?php // file: login_frame.php ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
<html xmlns="http://www.w3.org/1999/xhtml&quot;&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Wavinet</title>
</head>
<frameset rows="1,*" frameborder="no" border="0" framespacing="0">
<frame src="topFrame.php" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
<frame src="login_dfr.php" name="mainFrame" id="mainFrame" title="mainFrame" />
</frameset>
<noframes>
<body>This page contain frame</body>
</noframes>
</html>
+1  A: 

Your code doesn't really make sense, unless I'm misunderstanding it. You're generating a form entirely with information already available to PHP, and submitting it back to PHP. There's no reason, you can just include whatever file $data['url'] points to in your script and give it the username and password directly

Michael Mrozek
A: 

That should work fine, assuming the generated html is not mangled by your lack of escaping the values of the php variables.

Your problem might be in your script which receives the post. Do a print_r($_POST); to help you debug.

But, like Michael Mrozek said, you probably don't need to do this at all.

chris
A: 

You probably need to give IE time to render the form before you make it submit it. So this with

<script language="javascript" type="text/javascript">
setTimeout(function() {
    document.forms["frm_redirect_dfr"].submit();
    }, 0) /* You may need a higher number here. If you do, start with 100 and go up. */
</script>

You could also hang it off a document ready handler or something similar, but I don't know the raw JavaScript to do it (jQuery provides just such a hook, though).

The reason this works is that it's a type of 'yield'. Browsers tend to give lower priority to rending the page elements than executing inline JavaScript. This presents a problem with inline JavaScript has to interact with the DOM as there is no obvious way to wait for the browser to render it. This trick gives the browser an opportunity to get some rendering done before more JavaScript runs.

staticsan
thanks for the answer staticscan, but when I try your code, it doesn't work, the action URL still showing "You have to login" page. I change the number to 5000. I also have try using jquery, and it also doesn't workOne new question appear on my mind, are the post data sent to the action URL. I have check it on firefox using LiveHTTPHeader, the post data is sent. I don't know how to debug the HTTP Header on IE since there are no LiveHTTPHeader for IE
Permana
Okay, so you need to do your debugging in server-side code. Frist, use View Source to verify that the form tag's action parameter is going to the correct URL. Then use `print_r($_POST); exit;` to tell you exactly what the server is being sent.
staticsan
the form data was submitted. The POST data is sent, I just check using fiddler
Permana
fiddler tells you the data is sent -- you're not checking to see what the PHP code on the server is getting. If my car has an acceleration problem, I have to do more than check that the pedal is pulling the throttle cable.
staticsan