nicolette Posted June 30, 2010 Share Posted June 30, 2010 hi i'm new to php so if you would please help me out that would be great! I need to make a form with a list box that will contain search engines when the user selects a site that site will open in a new window. I know how to make the basic form but for the life of me i can't get it to pass the url of the search engine I'm sure this is really easy but i just can't figure it out thanks Link to comment https://forums.phpfreaks.com/topic/206333-url-question/ Share on other sites More sharing options...
marcus Posted June 30, 2010 Share Posted June 30, 2010 <form method="post"> Choose Your Website: <select name="url"> <option value="http://google.com">Google</option> <option value="http://yahoo.com">Yahoo</option> <option value="http://bing.com">Bing</option> </select> <input type="submit" name="submit" value="Go to Search Engine"> </form> <?php if(isset($_POST['submit'])){ $urls = array('http://google.com','http://yahoo.com','http://bing.com'); if(in_array($_POST['url'],$urls)){ header("Location: " . $_POST['url']); }else { echo "<p>Invalid Search Engine!</p>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/206333-url-question/#findComment-1079369 Share on other sites More sharing options...
nicolette Posted June 30, 2010 Author Share Posted June 30, 2010 Hi thanks, I am getting a header error here is the code you gave me edited to my pre-existing form <HTML> <head> <title> Final Part 2</title> <body> <h2>Please Select a search engine.</h2> <form method="POST"target="_blank"> <table> <tr> <td>Sites: </td> <td> <select name="url"> <option value="http://yahoo.com">Yahoo.com</option> <option value="http://google.com">Google.com</option> <option value="http://ask.com">Ask.com</option> <option value="http://lycos.com">Lycos.com</option> <option value="http://bing.com">Bing</option> </select> </td> </tr> <tr> <td><input type="submit" name="SubmitPart2" value="<<< Go To" /></td> </tr> </table> </form> <?php if(isset($_POST['SubmitPart2'])) { $urls = array('http://yahoo.com','http://google.com','http://ask.com','http://lycos.com','http://bing.com'); if(in_array($_POST['url'],$urls)) { header("Location: " . $_POST['url']); } else { echo "<p>Invalid Search Engine!</p>"; } } ?> </body> Link to comment https://forums.phpfreaks.com/topic/206333-url-question/#findComment-1079379 Share on other sites More sharing options...
marcus Posted June 30, 2010 Share Posted June 30, 2010 Just throw that code to the top. try this <?php if(isset($_POST['SubmitPart2'])) { $urls = array('http://yahoo.com','http://google.com','http://ask.com','http://lycos.com','http://bing.com'); if(in_array($_POST['url'],$urls)) { header("Location: " . $_POST['url']); } else { $a = "<p>Invalid Search Engine!</p>"; } } ?> <HTML> <head> <title> Final Part 2</title> <body> <h2>Please Select a search engine.</h2> <?php echo $a; ?> <form method="POST"target="_blank"> <table> <tr> <td>Sites: </td> <td> <select name="url"> <option value="http://yahoo.com">Yahoo.com</option> <option value="http://google.com">Google.com</option> <option value="http://ask.com">Ask.com</option> <option value="http://lycos.com">Lycos.com</option> <option value="http://bing.com">Bing</option> </select> </td> </tr> <tr> <td><input type="submit" name="SubmitPart2" value="<<< Go To" /></td> </tr> </table> </form> </body> Link to comment https://forums.phpfreaks.com/topic/206333-url-question/#findComment-1079383 Share on other sites More sharing options...
nicolette Posted June 30, 2010 Author Share Posted June 30, 2010 Thanks! Link to comment https://forums.phpfreaks.com/topic/206333-url-question/#findComment-1079384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.