Zox
Zox

Reputation: 303

Javascript Redirect - Control It with Php

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

Answers (2)

chandresh_cool
chandresh_cool

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

DrColossos
DrColossos

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

Related Questions