Forums

Create a search form for a database table

momentis 14 Jun, 2012
I know I should be able to answer this myself, but I am at a loss.

I have a table in my database which contains staff contact information. I want a simple form which allows someone to search for a staff member by name. The form just needs a search box, a submit button and a reset button. When submitted, I want the form to open up a CC view which can list out the matching results.

I can create the form, and I can create the CC view. How can I make the submit button for the form open the CC view and process the search?

Thanks!!!
Rick
Max_admin 19 Jun, 2012
But CC already has a search box feature!!🙂

You may also set the form action url to the connection's main url and se the search field name and the submit button name to the same ones in the connection's search settings, I think this may work.
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
momentis 19 Jun, 2012
Yes it does, but how can I use the search box feature without actually showing the list? Plus, I want this to reside in a module position, and I know that I can use the CF Module for that purpose. Maybe I am just missing something? 😶

Thanks for the pointer - I will give it a try!!

Rick
GreyHead 20 Jun, 2012
Hi Rick,

I recently created a searchable list using just ChronoForms and the DB Multi-Record Loader. Here's the WHERE query code that gives you an empty list if there are no filter values by setting `id` = NULL as the default search
<?php
$form->data['where'] = '`id` = NULL';
$where = array();
if ( isset($form->data['sales_person']) && $form->data['sales_person'] ) {
  $where[] = " `Reg`.`sales_person` = '{$form->data['sales_person']}' ";
}
if ( isset($form->data['consumer_name']) && $form->data['consumer_name'] ) {
  $where[] = " `Reg`.`consumer_name` LIKE '%{$form->data['consumer_name']}%' ";
}
if ( isset($form->data['model_id']) && $form->data['model_id'] ) {
  $where[] = " `SerialNo`.`model_id` LIKE '%{$form->data['model_id']}%' ";
}
if ( isset($form->data['serial_no']) && $form->data['serial_no'] ) {
  $where[] = " `SerialNo`.`serial_no` LIKE '%{$form->data['serial_no']}%' ";
}
if ( count($where) ) {
  $form->data['where'] = implode(' AND ', $where);
}
?>

Bob
This topic is locked and no more replies can be posted.