I have a simple html form containing a textbox to accept user input and two radio buttons.
I need to send the data to a database search I've written or alternatively, to an ecommerce product search engine that I use.
Does anyone know how to do this using the radio buttons.
Thanks.
Search based on radio button selection
Moderator: General Moderators
I think this will guide you abit.
Code: Select all
<pre>
<form method="post">
<input type="text" name="text" value="Example" />
<input type="radio" name="theoption" value="Foo" checked />Foo</input>
<input type="radio" name="theoption" value="Bar" />Bar</input>
<input type="radio" name="theoption" value="Muu" />Muu</input>
<input type="radio" name="theoption" value="Kittythrow" />Kittythrow</input>
<input type="radio" name="theoption" value="Argh" />Argh</input>
<input type="submit" />
</form>
<?php
if (!empty($_POST)) {
echo 'Example Query:<br />';
echo '$sql = "select data from table where something = '''.$_POST['text'].''' and another = '''.$_POST['theoption'].'''';
}
echo '<br />';
print_r($_POST);
?>Sorry. I wasn't clear in explaining my problem.
My radio button selection needs to do two things.
1) Send data to a sql statement if radio button 1 is 'checked'
2) Else, send data to ecommerce search engine (As you would using the normal action='search_engine_url.php')
This is probably really simple, but I can't see past step 2.
Any help would be greatly appreciated.
My radio button selection needs to do two things.
1) Send data to a sql statement if radio button 1 is 'checked'
2) Else, send data to ecommerce search engine (As you would using the normal action='search_engine_url.php')
This is probably really simple, but I can't see past step 2.
Any help would be greatly appreciated.
First idea was headers().
Pseudo code:
Result: http://www.example.com/search/index.php ... foo%20here
In the search-engine page you can later use $_GET['q'] (something%20foo%20here, using the example variable above), to get the string that you need to use in ther search clause.
Read up on:
http://se.php.net/manual/sv/function.header.php
Interesting also: (for transporting strings safely in the URI being one issue)
http://se.php.net/manual/sv/function.rawurlencode.php
http://se.php.net/manual/sv/function.serialize.php
http://se.php.net/manual/sv/function.base64-encode.php
Hope I gave better ideas now.
Pseudo code:
Code: Select all
if (radio1 == true) {
// query database
} else {
header('Location: http://www.example.com/search/index.php?q='.$_POSTї'text_string']);
}In the search-engine page you can later use $_GET['q'] (something%20foo%20here, using the example variable above), to get the string that you need to use in ther search clause.
Read up on:
http://se.php.net/manual/sv/function.header.php
Interesting also: (for transporting strings safely in the URI being one issue)
http://se.php.net/manual/sv/function.rawurlencode.php
http://se.php.net/manual/sv/function.serialize.php
http://se.php.net/manual/sv/function.base64-encode.php
Hope I gave better ideas now.
This is the code I have.
I don't have access to the eccomerce productsearch.cgi file, so I can't make any changes. How do I send data to this file. Without using headers. If I use headers, it brings back an error saying that the headers have already been sent.
Normally the form action would be set to point to the ecommerce URL
Thanks
Code: Select all
<form method="post">
<br>
<input name="search_field" type=text class="searchboxes" size="15">
<input type=hidden name="storeid" value="spint1">
<input name="submit2" type="image" value="Search" src="images/go1.gif" align="middle" width="28" height="30">
<br>
<span class="searchboxtext">
<input name="searchradio" type="radio" value="Archives" checked>
Archives
<input name="searchradio" type="radio" value="Products">
Products</span>
</form>Code: Select all
<?php
$radio = $_POST['searchradio'];
if ($radio == 'Archives')
{
// Gets send to the sql query (This is fine)
}
else if ($radio == 'Products')
{
// This gets sent to eccomerce site with url: http://spintelligent.com/shopsite_sc/sh ... eid=spint1
}
?>Normally the form action would be set to point to the ecommerce URL
Thanks
$_POST['searchradio'] should contain either Archives or Products as value.
<input name="searchradio" type="radio" value="Products">
name = what you use when fetching the data in $_POST/$_GET.
value = what the name above contains.
The headers sent issue is discussed here: viewtopic.php?t=1157
Don't give up & test some more.
<input name="searchradio" type="radio" value="Products">
name = what you use when fetching the data in $_POST/$_GET.
value = what the name above contains.
The headers sent issue is discussed here: viewtopic.php?t=1157
Don't give up & test some more.