Search with Radio Buttons

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

Hi, All -

I have a situation in which records on the site exist on two separate tables. For simplicity we'll call them "cms_articles" and "cms_news".

I want to set up a simple search facility which will give users the option of searching either table. Users would select Articles or News by means of a radio button before hitting the search button.

I am familiar with setting up searches in CMSB but I have no idea how to add the radio button functionality. Any help would be most welcome.

:0)

Perch

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