0

I'm trying to make this work but there something wrong:

<?php
if(isset($_POST['submit'])){
    echo "<script>location='https://google.com'</script>";
exit();
}
?>

<html>
<head>

<script>
    function onSubmit() {
        document.getElementById('menu_post').value = 'main';
        document.forms['MenuForm'].submit();
    }

</script>

</head>
<body>

<a onclick="onSubmit();return false;" href="javascript:void(0)">Test</a>

<form name="MenuForm" method="post" action="index.php">
    <input type="hidden" id="menu_post" name="menu_post" value="" />
</form>

</body>
</html>

I tried this one [php on submit redirect to another page

But still doesn't work.

Thanks in advance for any help guys.

  • 1
    Possible duplicate of [jQuery page redirect after submit the form](https://stackoverflow.com/questions/23822566/jquery-page-redirect-after-submit-the-form) – Ugur Kazdal Dec 06 '18 at 13:58
  • Just out of curiosity what is the context for this because there's much better ways of achieving what you're doing here? – Paddy Hallihan Dec 06 '18 at 14:06

1 Answers1

0

It should be something like:

if(isset($_POST['submit'])){
    echo "<script>window.location.href='https://google.com'</script>";
    exit();
}

Edit

You've actually nothing being posted as 'submit'.

if(isset($_POST['menu_post'])){
    echo "<script>window.location.href='https://google.com'</script>";
    exit();
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Paddy Hallihan
  • 1,624
  • 3
  • 27
  • 76