crazyglue71 Posted July 9, 2009 Share Posted July 9, 2009 how can i take user input from a form and convert it to a text string. so say the user enters in the text form "looking for something" and clicks submit it would redirect the user to http://mysite.com/page/looking-for-something is this possible? thank you Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/ Share on other sites More sharing options...
The Eagle Posted July 9, 2009 Share Posted July 9, 2009 Hello CrazyGlue You're referring to, well I do believe, a search tab feature on your website. At the time being, I am not aware of a way for them to be able to be redirected to a certain part of a website with text entry. I know of a way, with includes Javascript, of them to click a button (radio button) and be redirected to a page specified by the code. Let me know, but I will look into this for you. Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/#findComment-872362 Share on other sites More sharing options...
crazyglue71 Posted July 9, 2009 Author Share Posted July 9, 2009 this is what i have its an autosuggest script <input class="input" name="input" type="text" id="input1" size="30" maxlength="1000" src="/images/search.jpg" onkeyup="autoSuggest(this.id, 'listWrap1', 'searchList1', 'input1', event);" onkeydown="keyBoardNav(event, this.id);" /> <input type="submit" name="search" id="search1" value="submit" /> when you click submit nothing happens i mean can you not take the information from the input box and somehow use onClick="location.href='/page/input from text box will appear here'" Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/#findComment-872368 Share on other sites More sharing options...
The Eagle Posted July 9, 2009 Share Posted July 9, 2009 After investigating into your issue, I do believe a search engine would most fit your needs. You can use one of the free ones (e.g: Google Search Engine, Pax.com Search tab). You may also use the one I've made temporarily Below is the HTML to your webpage, so it may be searched. <html> <head> <title>Web Search</title> </head> <form name="form1" method="POST" action="search.php"> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="36%"> <div align="center"> <input type="text" name="keyword"> </div> </td> <td width="64%"> <input type="submit" name="Submit" value="Search!"> </td> </tr> </table> </form> </body> </html> Then you should create a file named "search.php". Put the following code into this new file. <?php function listFiles($dir){ $handle=opendir($dir); while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."){ //if it is a directory, then continue if(is_dir("$dir/$file")){ listFiles("$dir/$file"); } else{ //process the searching here with the following PHP script } } } } function listFiles($dir,$keyword,&$array){ $handle=opendir($dir); while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."){ if(is_dir("$dir/$file")){ listFiles("$dir/$file",$keyword,$array); } else{ //read file $data=fread(fopen("$dir/$file","r"),filesize("$dir/$file")); //avoid search search.php itself if($file!="search.php"){ //contain keyword? if(eregi("$keyword",$data)){ $array[]="$dir/$file"; } } } } } } //define array $array $array=array(); //execute function listFiles(".","php",$array); //echo/print search results foreach($array as $value){ echo "$value"." \n"; } ?> Now, combine the programs listed above, you will find all the related results in your websites will be found and listed. A further optimization of the search engine can be taken by adding the following, 1,list the title of all searching results REPLACE THE FOLLOWING if(eregi("$keyword",$data)){ $array[]="$dir/$file"; } WITH if(eregi("$keyword",$data)){ if(eregi("<title>(.+) </title>",$data,$m)){ $title=$m["1"]; } else{ $title="no title"; } $array[]="$dir/$file $title"; } 2,Add links to searching results CHANGE THE FOLLOWING foreach($array as $value){ echo "$value"." \n"; } TO foreach($array as $value){ list($filedir,$title)=split("[ ]",$value,"2"); echo "$value"." \n"; } // ADD THE FOLLOWING AT THE BEGINNING OF PHP FILES set_time_limit("600"); set_time_limit("600"); $keyword=trim($_POST["keyword"]); if($keyword==""){ echo"Please enter your keyword"; exit; } function listFiles($dir,$keyword,&$array){ $handle=opendir($dir); while(false!==($file=readdir($handle))){ if($file!="."&&$file!=".."){ if(is_dir("$dir/$file")){ listFiles("$dir/$file",$keyword,$array); } else{ $data=fread(fopen("$dir/$file","r"),filesize("$dir/$file")); if(eregi("<body([^>]+)>(.+)</body>",$data,$b)){ $body=strip_tags($b["2"]); } else{ $body=strip_tags($data); } if($file!="search.php"){ if(eregi("$keyword",$body)){ if(eregi("<title>(.+)</title>",$data,$m)){ $title=$m["1"]; } else{ $title="no title"; } $array[]="$dir/$file $title"; } } } } } } $array=array(); listFiles(".","$keyword",$array); foreach($array as $value){ list($filedir,$title)=split("[ ]",$value,"2"); echo "$title "." \n"; } If you wish, you may add this to the VERY top of the PHP code to alert the user when no words have been typed into the box. //get keywords $keyword=trim($_POST["keyword"]); //check if the keyword is empty if($keyword==""){ echo"no keywords"; exit; } ?> Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/#findComment-872370 Share on other sites More sharing options...
The Eagle Posted July 9, 2009 Share Posted July 9, 2009 After reading your second post, I do still believe a search engine will fit your needs. There is another possibility, I do not know if you're looking for this or not. It's called a radio button redirect, or as in my mind it is. It uses no PHP, and just Javascript, which may cause {slight} problems if the user has no Javascript enabled, so this may be a "last resort." <html> <head> <title>Radio Button Redirect</title> <SCRIPT type="Text/JavaScript" LANGUAGE="JavaScript"> <!-- Begin function go(loc) { window.location.href = loc; } // End --> </script> </head> <body> <td valign=top> <div><center> <form name="form" action="pagename.html"><b>Pick your choice:</b><br> <BR><table border=0 cellpadding=5><tr><td> <input type="radio" name="loc" style="color: #092445; background-color: #FFFFFF; border: 1px #ffffff solid;" onClick="go('pagename.html');" alt=""></td><td><font face=verdana size=2>Selection #1</font></td></tr><tr><td> <input type="radio" name="loc" style="color: #092445; background-color: #FFFFFF; border: 1px #ffffff solid;" onClick="go('pagename.html');" alt=""></td><td><font face=verdana size=2>Selection #2</font></td></tr><tr><td> <input type="radio" name="loc" style="color: #092445; background-color: #FFFFFF; border: 1px #ffffff solid;" onClick="go(''pagename.html'');" alt=""></td><td><font face=verdana size=2>Selection #3</font></td></tr><tr><td> <input type="radio" name="loc" style="color: #092445; background-color: #FFFFFF; border: 1px #ffffff solid;" onClick="go('pagename.html'');" alt=""></td><td><font face=verdana size=2>Selection #4</font></td></tr></table> <BR><BR><BR> </form> </html> It's useful in some situations. You may see a live demo of it on my website. http://www.vazzer.net/chooseyourclass.html I made that awhile ago, so don't mind the crazyness of it . Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/#findComment-872375 Share on other sites More sharing options...
joel24 Posted July 9, 2009 Share Posted July 9, 2009 if you had a form with text input called say userInputBox you could have $userInput = $_POST['userInputBox']; //change spaces to - $userInput = str_replace(' ', '-', $userInput); //redirect user to url header("location: page/$userInput"); exit(); Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/#findComment-872384 Share on other sites More sharing options...
crazyglue71 Posted July 10, 2009 Author Share Posted July 10, 2009 hi Joel my code looks like this i think what your suggesting would work but how would i place the code can you look below and see <div class="wrapSearch"> <div> <input class="input" name="input" type="text" id="input1" size="30" maxlength="1000" onkeyup="autoSuggest(this.id, 'listWrap1', 'searchList1', 'input1', event);" onkeydown="keyBoardNav(event, this.id);" /> <input type="submit" name="search" id="search1" value="Search" /> </div> <div class="listWrap" id="listWrap1"> <ul class="searchList" id="searchList1"> </ul> </div> </div> Thanks Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/#findComment-872410 Share on other sites More sharing options...
joel24 Posted July 10, 2009 Share Posted July 10, 2009 your input code needs to be inside a form... i.e. <div class="wrapSearch"> <div> <form action="<?php echo basename($_SERVER['PHP_SELF']); ?>" method="post"> <input class="input" name="input" type="text" id="input1" size="30" maxlength="1000" onkeyup="autoSuggest(this.id, 'listWrap1', 'searchList1', 'input1', event);" onkeydown="keyBoardNav(event, this.id);" /> <input type="submit" name="search" id="search1" value="Search" /> </form> </div> <div class="listWrap" id="listWrap1"> <ul class="searchList" id="searchList1"> </ul> </div> </div> that form will post the contents to itself.. and the php will pick it up.. put the php in the very top of the page! before any <html> <head> etc if (isset($_POST['input']) && !empty($_POST['input']) { $userInput = $_POST['input']; //change spaces to - $userInput = str_replace(' ', '-', $userInput); //redirect user to url header("location: page/$userInput"); exit(); } that will redirect the user to www.mydomain.com/whatever/page/user-input what did you want to try and achieve from this? Link to comment https://forums.phpfreaks.com/topic/165411-solved-form-output/#findComment-872420 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.