[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

redirect in submit statement

echo '<input type="submit" name "click" value="click">';

is there a way to redirect to another page in this statement

echo '<input type="submit" name "click" value="click" location"www.website.com">';
0
rgb192
Asked:
rgb192
  • 2
  • 2
2 Solutions
 
Beverley PortlockCommented:
The usual method for doing this with a SUBMIT button is to catch the submit and then use a header statement. So the user presses the SUBMIT button in your INPUT statement

echo '<input type="submit" name "click" value="click">';

and you do this

<?php

     if ( isset($_POST['submit'] ) )  { // or $_GET if you are using that
          header("Location: http://www.website.com");
          exit;
     }

     .... rest of PHP code
0
 
Srobinson08Commented:
What are you trying to achieve with the above? Are you trying to redirect the user onclicking the button?

The below code will work if thats what your triyng to do!

echo '<input type="button" name "click" value="click" onclick="document.location = /'page_to_goto.html/'>';
0
 
Beverley PortlockCommented:
Srobinson08 - the reason I did not suggest that is if there is a form button then that suggests a form and therefore input fields to process. Perhaps I should have made that more explicit.

If the button is going to redirect immediately on pressing then the O/P might as well use a link rather than a button.

Anyway, with all that in mind, I'll modify my initial example like so


<?php

     if ( isset($_POST['submit'] ) )  { // or $_GET if you are using that

          ..... process other fields....

          header("Location: http://www.website.com");
          exit;
     }

     .... rest of PHP code
0
 
Srobinson08Commented:
Thanks for the update.

I assumed that the user would have just used a form action if they wished to process the form values then redirect which is why i just had the standalone button. But yes, your solution is preffered!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now