• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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