Search with Radio Buttons

5 posts by 3 authors in: Forums > CMS Builder
Last Post: October 9, 2013   (RSS)

Hey Perch,

Just random thoughts. Haven't worked through the process. But how about a start of 2 radio buttons with same name.

One radio button with the value articles and the other one with the value news. Then if statements to determine the correct table to search.

Hope that helps in some way.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi, Jerry -

Thanks for your note. I was on the same path. I've managed to get it working - but it's a bit restrictive.

<form action="search.php" method="get">
  <input type="text" name="q" maxlength="35" placeholder="Search"  value="<?php echo htmlspecialchars(@$FORM['q']); ?>" >
  <input type="table" name="table" value="arts" />
  Articles
  <input type="table" name="table" value="news" />
  News
  <input class="search-submit" type="submit" />
</form>

What I would like to do is somehow change the key-value parts of the query string (hi-lighted in red above). The default is:

q=searchterm

It would be nice if I could somehow change this according to which radio button is pressed.

So, if the Articles button were depressed it would be:

arts=searchterm

And if News is selected it would be:

news=searchterm

Or something along these lines.

:0s

Perchpole

Update!

Actually, this does work...

<form action="search.php" method="get">
  <input type="text" name="<?php @$GET['table'] ?>" maxlength="35" placeholder="Search"  value="<?php echo htmlspecialchars(@$FORM['q']); ?>" >
  <input type="table" name="table" value="arts" />
  Articles
  <input type="table" name="table" value="news" />
  News
  <input class="search-submit" type="submit" />
</form>

More experimentation needed!

:0)

Perch

By ross - October 9, 2013

Hi Perchpole

I'll let Jerry get back to you on his idea and wanted to share mine with you :).

If I understand what you are aiming for, you could just make the value of each radio button the same as the table name you want it to search. A really basic example:

<form action="">
<input type="radio" name="searchTable" value="news">Search News<br>
<input type="radio" name="searchTable" value="arts">Search Arts
</form>

Then, on the results page, you would have your get records and put the value of the radio button as the table to load like this:

$searchTable = mysql_real_escape_string( @$_REQUEST['searchTable'] );

if ( !$searchTable ) { $searchTable = 'news'; }

list($searchResults, $searchResultsMetaData) = getRecords(array(
    'tableName'   =>  $searchTable ,
    'loadUploads' => true,
    'allowSearch' => false,
  ));

I added in the first two lines there so there is always a default value in $searchTable. This will take into account situations where a visitor will go directly to your search results page. 

Let me know if this helps :)!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/