Reputation: 303
Here is a script that i would like to use for redirection:
<form id="form1" method="post" action="http://yahoo.com">
<script language="javascript" type="text/javascript">
document.getElementById('form1').submit();
</script>
</form>
Now I have to control it with a php code, but this one doesn't work:
$redirect = '<form id="form1" method="post" action="http://google.com">
<script language="javascript" type="text/javascript">
document.getElementById('form1').submit();
</script>
</form>'
I guess there is a syntax error, but I am unable to figure it out. Please help.
Also let me know is it an ok redirect method that keeps the script execution page as referrer?
Upvotes: 0
Views: 272
Reputation: 11830
Try this, you need to escape single quotes
$redirect = '<form id="form1" method="post" action="http://google.com"> <script language="javascript" type="text/javascript">
document.getElementById(\'form1\').submit(); </script></form>';
Upvotes: 1
Reputation: 12988
You are getting the '
wrong inside getElementById
$redirect = '<form id="form1" method="post" action="http://google.com">
<script language="javascript" type="text/javascript">
document.getElementById("form1").submit();
</script>
</form>'
By the way, this is a unusual way of doing the redirect. Why not use window.location.href
instead?
Or a PHP header redirect?
header("Location: http://www.google.com/");
Upvotes: 3