mandan Posted May 12, 2009 Share Posted May 12, 2009 I am looking for php solution and not for javascript solution for the following: The form has one textbox (type=text name=firstName) and one button (value=Search, type=submit). The user enters the data and clicks on 'Search' button. Once the 'Search' button is clicked, 1. The code must verify that the length of the string entered in the textbox is greater than 1 ( > 1). 2. If textbox string is greater than 1, do the following: a new window is opened (target="_blank" ??) and the URL will be for e.g. "http://mouse.ca/search/eatable/books/find?settings=silent&query="+TheDataThatWasEnteredInTextBoxFirstName 3. If textbox string is less than or equal to 1 (<=1). Nothing happens. (The user is on the form page with one textbox and one button with whatever he/she entered in the textbox) PHP please, NO javascript. Please help. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/ Share on other sites More sharing options...
allworknoplay Posted May 12, 2009 Share Posted May 12, 2009 I don't think you can open a new window without javascript.... Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-832638 Share on other sites More sharing options...
karan23424 Posted May 12, 2009 Share Posted May 12, 2009 you can simply use the header function to jump on another site Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-832762 Share on other sites More sharing options...
karan23424 Posted May 12, 2009 Share Posted May 12, 2009 you can also use the window.open after reciving the input text from the user window.open("url?<?php $var1&$var2 ?>"); Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-832779 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 karan, you need echo. Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-832782 Share on other sites More sharing options...
mandan Posted May 13, 2009 Author Share Posted May 13, 2009 I am not familiar with php as I have been using .net for too long. If a new window cannot be opened, let that condition be omitted. I would like to know the detailed steps / code on how to grab the info. in the textbox, check it for one or more characters and add the URL part and redirect it to the mentioned URL along with the textbox input. Once again I am a beginner and a detailed code/explanation will be helpful. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-832949 Share on other sites More sharing options...
xtopolis Posted May 13, 2009 Share Posted May 13, 2009 Data submitted by a form can be accessed via the superglobals. $_POST and $_GET You access the data via the name attribute of the field being sent, in your case it would either be: $_POST['firstName'] or $_GET['firstName'] (since you didn't specify your method). This is a small example tutorial. To check the length of a string, use the strlen function. In PHP, you cannot "do nothing" when a form is submitted, and I assume likewise in .NET. The "do nothing" event would be handled by javascript intercepting the submit and acting accordingly. You can however direct the application flow after submission based on whether it meets your requirements (ie strlen > 1). That part is just common logic statements: if(strlen($_POST['firstName']) > 1) { //do something }else{ //could show the form again, with fields filled in, or an error } As for redirecting, you can use header to redirect as long as nothing (NOTHING) has been output to the page... you can also append your firstName data perhaps more confidently when cleaning it with urlencode and maybe htmlentities. $fn = htmlentities(urlencode($_POST['firstName'])); header('Location: http://www.examplesite.com/query=' . $fn); Please look into the functions in the manual as they will help out a lot. Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-832969 Share on other sites More sharing options...
mandan Posted May 14, 2009 Author Share Posted May 14, 2009 Thanks to all of you and a special thanks to 'xtopolis'. How do I close this issue or mark it as solved? Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-834203 Share on other sites More sharing options...
Philip Posted May 14, 2009 Share Posted May 14, 2009 Solved button is in the bottom left corner of the page, under the thread Quote Link to comment https://forums.phpfreaks.com/topic/157862-get-data-from-textbox-and-redirect-to-another-site-attaching-the-textbox-info/#findComment-834205 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.