Forum Moderators: coopster
e.g.
when the user enters
search="fab widgets"
drop-down="widget.com"
he is taken to....
http://www.example.com/widget.asp?searchtype=allproducts&searchstring=fab+widgets
How do I do this? Do I need to create a PHP script to handle the form?
Thanks, Pete
[edited by: tedster at 8:52 pm (utc) on Dec. 6, 2004]
[edit reason] use example.com [/edit]
<html><HEAD><TITLE></TITLE></HEAD></BODY><form method="get" action="foo.cgi">
<INPUT TYPE="text" NAME="term"><br>
<select name="url">
<option value="widget.com">widget.com</option>
<option value="wadget.com">wadget.com</option>
<option value="wudget.com">wudget.com</option>
</select><input type="button" name="myButton" onclick="buildURL(this.form)" value="Send it">
</form><script language="Javascript">
function buildURL(form) {
var str,fld,val = '';
var sendIt=false;
str = 'http://.www';for (i=0;i<form.elements.length;i++) {
var obj = form.elements[i];
if (obj.name!= 'myButton') {
fld = escape(obj.name); //in case you use special characters
if (obj.type=='select-one') {
val = obj.options[obj.selectedIndex].value;
}
else { val = obj.value; }
if (val!= '') {
val = escape(val);
str += obj.name+'='+val;
if (i< (form.elements.length-2)) { str += '&'; }
}
}
}
sendIt = confirm('OK to send " ' + str + ' "?');
if (sendIt == true) { form.submit(); } // or document.location=str, since it's get
else { alert('URL string " ' + str + ' " cancelled.'); }
}</script>
</body>
</html>
There's no reason that redirect should be slow. So I take it you figured out how to use $_GET to break out the search terms and you are redirecting based on those?
All of those steps should be quite fast. It sounds like you're redirecting to a merchant on another server. Could it be the merchant server is slow?
Tom
It's not a $get command, but rather a language feature in PHP. PHP has a set of so-called "super-global" variables. These variables are available anywhere in your script, even inside functions where normally only local variables are available.
One of these is $_GET which contains all parameters sent as part of a query string.
[example.com?q=qword&t=time...]
would yield two get parameters
$_GET['q'] with a value of "qword"
$_GET['t'] with a value of "time"
Sometimes you can access these values like so
$t with a value of "time"
This happens when register_globals [us2.php.net] is on. Generally this is considered sloppy and somewhat dangerous practices. It is not inherently insecure, as many people contend, but it's more a matter of making your code less secure. For example, you can also use the "post" method to pass data. So if I have
$_POST['t']
$_GET['t']
and register globals is on, what is the value of $t?
Tom