Create a form to search from Frontend like in CC

mi mikiglesias 19 Nov, 2010
Hello all,
I have been reading this forum for a week but I can not find the solution to my problem...so I will try to open a post with the issue. Thanks in advance.

I have created a form in CC to save data into the DB, it works fine and it is great!!!

My problem is that I want to have a similar form to search from fronted into the DB.

I tried to copy my form and change on it the method POST by GET....and tried to use it in frontend but nothing appears.

I get to create some fields to search....but my problems are:

1.- How to include the dropdown values in this search, as it is in the save data form? (see attachment with the save data form).

2.- Is it possible to have only the search fields and the search button (not all the entries unfiltered below) and then when it is pushed, show the entries retrieved as link to READ more in each one with click?

3.- Is it possible to have as search options the checkbox as in the save data form?


Thanks in advance for your help!!!!

Miki
mi mikiglesias 20 Nov, 2010
Thanks!
Finally, I get the desired layout for search, but I can not put the condition fields in the where clause....can somebody help me?

This is the head:
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Ciudad</label>
    <select class="cf_inputbox validate-selection" id="select_9" size="1" title=""  name="ciudad">
    <option value="">Elige una ciudad</option>
      <option value="Todas">Todas</option>
<option value="Málaga">Málaga</option>
<option value="Madrid">Madrid</option>
<option value="Barcelona">Barcelona</option>
<option value="Valencia">Valencia</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Título</label>
    <input class="cf_inputbox" maxlength="150" size="30" title="" id="titulo" name="titulo" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
 
</div>

<div class="form_item">
 
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Precio aproximado por persona</label>
    <select class="cf_inputbox" id="select_11" size="1" title=""  name="precio">
    <option value="">Elige una opción</option>
      <option value="Todos">Todos</option>
<option value="Gratis">Gratis</option>
<option value="0-5 €">0-5 €</option>
<option value="6-10 €">6-10 €</option>
<option value="11-50 €">11-50 €</option>
<option value="51-100 €">51-100 €</option>
<option value="Más de 100 €">Más de 100 €</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Duración aproximada</label>
    <select class="cf_inputbox" id="select_11" size="1" title=""  name="duracion">
    <option value="">Elige una opción</option>
      <option value="Todas">Todas</option>
<option value="Menos de 1 hora">Menos de 1 hora</option>
<option value="Entre 1 y 3 horas">Entre 1 y 3 horas</option>
<option value="Más de 3 horas">Más de 3 horas</option>
<option value="Varios días">Varios días</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Mes</label>
    <select class="cf_inputbox" id="select_12" size="1" title=""  name="mes">
    
      <option value="Todos">Todos</option>
<option value="Enero">Enero</option>
<option value="Febrero">Febrero</option>
<option value="Marzo">Marzo</option>
<option value="Abril">Abril</option>
<option value="Mayo">Mayo</option>
<option value="Junio">Junio</option>
<option value="Julio">Julio</option>
<option value="Agosto">Agosto</option>
<option value="Septiembre">Septiembre</option>
<option value="Octubre">Octubre</option>
<option value="Noviembre">Noviembre</option>
<option value="Diciembre">Diciembre</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_checkbox">
    <label class="cf_label" style="width: 150px;">Tipo de actividad</label>
    <div class="float_left">
      <input value="Para niños" title="" class="radio" id="check00" name="check0[]" type="checkbox" />
      <label for="check00" class="check_label">Para niños</label>
      <br />
      
<input value="Cultural(cines, museos,..)" title="" class="radio" id="check01" name="check0[]" type="checkbox" />
      <label for="check01" class="check_label">Cultural(cines, museos,..)</label>
      <br />
      
<input value="Naturaleza" title="" class="radio" id="check02" name="check0[]" type="checkbox" />
      <label for="check02" class="check_label">Naturaleza</label>
      <br />
      
<input value="Compras" title="" class="radio" id="check03" name="check0[]" type="checkbox" />
      <label for="check03" class="check_label">Compras</label>
      <br />
      
<input value="Deportes" title="" class="radio" id="check04" name="check0[]" type="checkbox" />
      <label for="check04" class="check_label">Deportes</label>
      <br />
      
<input value="Fiestas" title="" class="radio" id="check05" name="check0[]" type="checkbox" />
      <label for="check05" class="check_label">Fiestas</label>
      <br />
      
<input value="Gastronomía" title="" class="radio" id="check06" name="check0[]" type="checkbox" />
      <label for="check06" class="check_label">Gastronomía</label>
      <br />
      
<input value="Rutas" title="" class="radio" id="check07" name="check0[]" type="checkbox" />
      <label for="check07" class="check_label">Rutas</label>
      <br />
      
<input value="Otros" title="" class="radio" id="check08" name="check0[]" type="checkbox" />
      <label for="check08" class="check_label">Otros</label>
      <br />
      

    </div>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Buscar" name="button_8" type="submit" /><input type="reset" name="reset" value="Reset"/>
  </div>
  <div class="cfclear"> </div>
</div>



and this is the SQL:
 $title = JRequest::getString('titulo', 'mes' '', 'post');
<?php
if ( $title ) {
echo " WHERE `titulo` LIKE '%$titulo%' ";
}
?>


Is it possible to show the results in a new page?

thanks!
Gr GreyHead 21 Nov, 2010
Hi mikiglesias,

For the WHERE clause all the PHP must be inside the PHP tags
<?php
$title = JRequest::getString('titulo', 'mes' '', 'post');
if ( $title ) {
  echo " WHERE `titulo` LIKE '%$titulo%' ";
}
?>

Is it possible to show the results in a new page?

I'm sorry I don't understand this question.

Bob
mi mikiglesias 21 Nov, 2010
Thanks for the answer.
The second question was, if it is possible to have in a first step, the search options and search button, and then, when button is pushed, a new window, with only the results of the query..without search fields. Is it now clearer?
Gr GreyHead 22 Nov, 2010
Hi mikiglesias,

Ok , now I understand. There's no automatic way of doing this that I can think of. I guess that I'd probably put some code in the header box to hide the form if this was a search result - you could check for a value in the $_POST array.

Bob
mi mikiglesias 22 Nov, 2010
Thanks so much....
This looks better🙂

Now, a php issue...i am only an ABAP expert...I think that it is very easy....

In the database select, i have several fields (ciudad, mes, precio, duracion, titulo), but I do not know which ones have been populated by the user....how can I construct a where clause with all of them?
the problem is that if field is used in the select but it has the initial value (for exaple, 'choose a month'), then, nothing is selected.
With only one, it works fine.

Thanks once more in advance!!!


<?php
$ciudad = JRequest::getString('ciudad', '', 'post');
$mes = JRequest::getString('mes', '', 'post');
$precio = JRequest::getString('precio', '', 'post');
$duracion = JRequest::getString('duracion', '', 'post');
$titulo = JRequest::getString('titulo', '', 'post');

if ( $ciudad )  
{
echo " WHERE ( `ciudad` LIKE '%$ciudad%' )
";
}

?>
Gr GreyHead 22 Nov, 2010
Hi mikiglesias,

Please see the Combining Filters section in the ChronoConnectivity Dynamic Filters 2 doc here

Bob
mi mikiglesias 23 Nov, 2010
I think that I must to create a dynamic where...but something must be wrong...

Can anybody find my error?

Thanks!!

this is my WHERE:
<?php
$ciudad = JRequest::getString('ciudad', '', 'post');
$mes = JRequest::getString('mes', '', 'post');
$precio = JRequest::getString('precio', '', 'post');
$duracion = JRequest::getString('duracion', '', 'post');
$titulo = JRequest::getString('titulo', '', 'post');

$where1 = " and ( 'ciudad' LIKE '%$ciudad%' )";
$where2 = " and ( 'mes' LIKE '%$mes%' )";
$where3 = " and ( 'precio' LIKE '%$precio%' )";
$where4 = " and ( 'duracion' LIKE '%$duracion%' )";
$where5 = " and ( 'titulo' LIKE '%$titulo%' )";

$cadena = " 'cf_id' > 0";

if ( $ciudad )  
{
  $cadena = $cadena.$where1 ;
}

if ( $mes )  
{
  $cadena = $cadena.$where2 ;
}

if ( $precio )  
{
  $cadena = $cadena.$where3 ;
}

if ( $duracion )  
{
  $cadena = $cadena.$where4 ;
}

if ( $titulo )  
{
  $cadena = $cadena.$where5 ;
}

if ( $cadena )

{
echo " WHERE $cadena";
}


?>
Gr GreyHead 11 Dec, 2010
Hi mikiglesias,

Sorry for the delay, I've just re-found this post.

I think that your code will always give WHERE AND . . . which is invalid MySQL. Try this more general version:
<?php
$string_array = array('cuidad', 'mes', 'precio', 'duracion', 'titulo');
$where = array();
foreach ( $string_array as $v ) {
  $temp = JRequest::getString($v, '', 'post');
  if ( $temp) {
	  $where[] = "( '$v' LIKE '%$$v%' )";
  }
}
if ( count($where) ) {
  echo " WHERE ".implode(' AND ', $where);
}
?>

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