jpedrofs Posted January 2, 2008 Share Posted January 2, 2008 Hey guys, I am a beginner trying to figure out how to create a button that redirects you to a website address extracted from a textbox. My attempt goes below: <form method="post" action="<?php $_POST['textbox']; ?>" /> <input type="text" name="textbox" id="textbox" /> <input name="criarblog" type="submit" id="submit" value="submit" /> </form> I haven't managed to put it working. Thanks for any help, Pedro Quote Link to comment Share on other sites More sharing options...
suttercain Posted January 2, 2008 Share Posted January 2, 2008 So you want the user to enter the address, www.domain.com, into a text box and have them taken to that site? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 Where is the information in the text box coming from? Quote Link to comment Share on other sites More sharing options...
jpedrofs Posted January 2, 2008 Author Share Posted January 2, 2008 Hi adam and suttercain, It is as you say suttercain, the information comes from a textbox that is available in the webpage. The user introduces an address in the textbox and when the submit button is clicked, there is a redirection to the webpage in the textbox. Pedro Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 this may work not 100% sure though <?php $a= $_POST[‘textbox’]; if(isset($_POST[‘textbox’])) { header('Location: $a'); } else { ?> <form action="<?=$_SERVER["PHP_SELF"]?>"... <input type="text" name="textbox" id="textbox" /> <input name="criarblog" type="submit" id="submit" value="submit" /> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
jpedrofs Posted January 2, 2008 Author Share Posted January 2, 2008 It is already redirecting to: http://mydomain.com/index.php?textbox=http://whatever.com&criarblog=submit but not yet to: http://whatever.com Any hints? Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 post all the code. Can't help without see whats going on Quote Link to comment Share on other sites More sharing options...
jpedrofs Posted January 2, 2008 Author Share Posted January 2, 2008 I just introduced your code suggestion and tried some tweaks, but came back to your original code: <?php $a= $_POST[‘textbox’]; if(isset($_POST[‘textbox’])) { header('Location: $a'); } else { ?> <form action="<?=$_SERVER["PHP_SELF"]?>" /> <input type="text" name="textbox" id="textbox" /> <input name="criarblog" type="submit" id="submit" value="submit" /> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 change to this <?php $a= $_POST[‘textbox’]; if(isset($_POST[‘textbox’])) { header('Location: http://$a'); } else { ?> <form action="<?=$_SERVER["PHP_SELF"]?>" /> <input type="text" name="textbox" id="textbox" /> <input name="criarblog" type="submit" id="submit" value="submit" /> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
aschk Posted January 2, 2008 Share Posted January 2, 2008 I want to clear something up for jpedrofs. I can see what you're attemping to do, but your understanding is skewed. The first time you load your form it looks something like this : <form method="post" action="" /> <input type="text" name="textbox" id="textbox" /> <input name="criarblog" type="submit" id="submit" value="submit" /> </form> When you click the submit button it will post to the page "" (blank). Now assuming the web browser obliges and guesses that you actually wanted to POST to the same page you are on, you might get lucky, and it'll reload the page you were just on, POST'ing the contents of the textbox to itself. Thus on you 2nd run your form will look something like this : <form method="post" action="whatever-i-typed-in-the-previous-box.com" /> <input type="text" name="textbox" id="textbox" /> <input name="criarblog" type="submit" id="submit" value="submit" /> </form> And on clicking submit again, you'll get lucky and end up on the page you wanted. Have a think about the above, and i'm sure you'll start to see where you were going wrong. Quote Link to comment Share on other sites More sharing options...
jpedrofs Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks for your thoughts. I will continue to work on it and will get back to you guys. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2008 Share Posted January 2, 2008 correct way....... <?php ob_start(); // incase if($_POST['submit']){ $textbox=$_POST['textbox']; header("Location: $textbox"); exit; } ob_flush(); // incase ?> <form method="POST" action=" "> <input type="text" name="textbox" > <input name="submit" type="submit" value="submit"> </form> Quote Link to comment Share on other sites More sharing options...
jpedrofs Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks redarrow. Works perfectly. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2008 Share Posted January 2, 2008 ok m8 anytime Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 2, 2008 Share Posted January 2, 2008 this was fun aswell type http://www.google.com <?php $x=array('http://www.google.com','http://www.msn.com','http://www.yahho.com'); if($_POST['submit']){ $url=$_POST['url']; if(in_array("$url",$x)){ echo " congratulations goto <a href='$url'>>>here<<<a/>"; exit; }else{ echo "sorry we have no $url of this type please try agin <a href='".$_SERVER['PHP_SELF']."'>>>here<<<a/>"; exit; } } echo"<center> <form method='POST' action=' '> <br><br> please provide your url <br> The name off the website<br> example http://www.google.com! <br><br> <input type='text' name='url'> <br><br> <input type='submit' name='submit' vlaue='Send'> </form> </center>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.