View Full Version : Form Redirection Query
halifaxer
08-30-2007, 11:46 AM
Hello all,
I have a form on my website
echo '<form action="/search.php" method="GET">';
echo 'Search: <input type="text" name="search">';
echo '<input type="submit" value="Go!">';
echo '</form>';
when the "Go!" is activated I need it to return the input from the user as such
/search.php?startrow=0&search=whatever
However no matter what I try, all it will ever return is
/search.php?search=whatever
I can't impliment my startrow anywhere. Have tried in the FORM ACTION. Have even tried to rename the INPUT TEXT to reflect, but it just doesn't work.
Is there a way for me to even get the startrow=0 up after what is submitted by user.
Much obliged,
boogyman
08-30-2007, 12:28 PM
you can put in a hidden input field
<input type="hidden" name="startrow" value="0">
but anyone would be able to view that in the source code of the file.
however I would like to know what the purpose of this startrow is going to be? certainly ifyou are using php to process the form, you shouldn't need an extra input in the form itself?
?>
<form action="/search.php" method="get">
<div>
<input type="hidden" name="startrow" value="0">
<label>
Search:
<input type="text" name="search">
</label>
<input type="submit" value="Go!">
</div>
</form>
<?phpDrop out of PHP parsing mode to output HTML, it makes for neater and more efficient code.
halifaxer
08-30-2007, 01:54 PM
excellent. thank you very much. i have one more question.
what loop could i use to obtain more than one word entered by the user.
EG. user enters "My Lovely Horse." Search will only equal "My"
i have: $search = $_Get['search'] in my code already. What loop could i put around that statement to make it search for any/all words entered by user taking into account the spacing
boogyman
08-30-2007, 02:03 PM
// EDIT
try this
$search = $_GET['search'];
echo $search;
that will tell you exactly what has been put into the search variable.
if you are only getting the My into the variable then its something in your processing before that is causing only the first word to show up.
if you get the full string entered, then we would need to see more of your code to determine where the rest of the string is being cut out.
as for getting everything that is entered in the search. you can use the
str_replace("search_term", "replace_with", "source");
to replace all of your spaces with a wildcard. however that can return results that you do not want, because it will than search for every word whether it be
"something", "anything", or "a".
so you just want to design it in a way to get rid of those common words,
Less than ideal: the words would have to be in order. Try:
... WHERE MATCH (mycolumn) AGAINST ('+my +lovely +horse' IN BOOLEAN MODE);
halifaxer
08-30-2007, 03:36 PM
this is the code i'm using to send the input from the user to the address bar on a new page where I call $_GET['search']. why would this only pass forward the first word of any input and can you help me solve it?
echo '<form action="/search.php" method="GET" style="margin-bottom:1px">';
echo '<a href="/">Home</a> | ';
echo '<a href="/whatsnew.php?startrow=0">What's New</a> | ';
echo '<a href="/newsletter.php">Newsletter</a> | ';
echo 'Search: <input type="text" name="search">';
echo '<input type="hidden" name="startrow" value="0">';
echo '<input type="submit" value="Go!">';
echo '</form>';
It doesn't, you're handling it wrong on the server side.
As I said above, you should break out of PHP parsing mode when writing HTML.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.