Welcome Guest, Not a member yet? Register   Sign In
Need Help - search form with multiple dropdown
#1

[eluser]mariuskmc[/eluser]
Greeting
I stumbled and hope someone can help me.

I need to do a search form with jquery for the following structure:

Category - dopdown
Country-(Country of Category) - dropdown
Oas - (city in the country and category) - Dropdown
Offer Name - Form input
Submit

I tried all the existing documentation ... But I did not create a functional variant.

It may help me with an example

sorry for my English
#2

[eluser]mariuskmc[/eluser]
Everything is ok as results turned
But some figures appear to display ...


first dropdown is ok ...

Dropdown 1
displays correctly only if I include dropdown 2 in a div with id

Dropdown 2
strangeness comes now ...
if included in a div dropdown2 no longer displays the third ....
if not included in a div - not displaying

Dropdown 3
it displays correctly only if it's plugged into div

In view
Code:
$(document).ready(function(){

    $('#selectcategorii').change(function() {
        $.ajax({
          type: "POST",
          url: "<?= base_url();?>cautare/arata_tari/" ,
          data: "idcategorie="+$('#selectcategorii').val(),

          success: function(data){
            $('#selecttari').html(data);
          }
        });
    });  

    $('#selecttari').change(function() {
        $.ajax({
          type: "POST",
          url: "<?= base_url();?>cautare/arata_oras/" ,
          data: "idtara="+$('#selecttari').val(),
          success: function(data){
            $('#selectorase').html(data);
          }
        });
    });  

});



Code:
<select name="categorii" id="selectcategorii">
&lt;?php $categorii=$this->Cautare_model->getcategoriiC(); ?&gt;
<option value="">- Categorii -</option>
&lt;?php foreach($categorii as $categorie) : ?&gt;
<option value="&lt;?php echo $categorie->idcategorie; ?&gt;">&lt;?php echo $categorie->numecategorie; ?&gt;</option>
&lt;?php endforeach; ?&gt;
</select>


<div id="selecttari">
<select name="selecttari" >

// initial value of dropdown 2  with all
&lt;?php $tari_toate=$this->Cautare_model->getAlltariC(); ?&gt;
<option value="">- Tari -</option>
&lt;?php foreach($tari_toate as $tara_toate) : ?&gt;
<option value="&lt;?php echo $tara_toate->idtara; ?&gt;">&lt;?php echo $tara_toate->numetara; ?&gt;</option>
&lt;?php endforeach; ?&gt;


</select>
</div>


<div id="selectorase">
<select name="selectorase" >

// initial value of dropdown 3 with all
<option value="">- Orase -</option>
&lt;?php $orase_toate=$this->Cautare_model->getAllOrasetoateC(); ?&gt;
&lt;?php foreach($orase_toate as $oras_toate) : ?&gt;
<option value="&lt;?php echo $oras_toate->idoras; ?&gt;">&lt;?php echo $oras_toate->numeoras; ?&gt;</option>
&lt;?php endforeach; ?&gt;
</select>
</div>

In controller
Code:
function arata_tari()
    {
        // Load location model
        $this->load->model('Cautare_model');

        // Which state to load?    
        $idcategorie = $this->input->post('idcategorie');
        
        $data['tari'] = $this->Cautare_model->gettaridincategorieC($idcategorie);
        
        $this->load->view('cautare/view_dropdown_tari', $data);
    }    
    
    function arata_oras()
    {
        // Load location model
        $this->load->model('Cautare_model');

        // Which state to load?    
        $idtara = $this->input->post('idtara');
        
        $data['orase'] = $this->Cautare_model->getAllOrasedintaraC($idtara);
        
        $this->load->view('cautare/view_dropdown', $data);
    }

In view view_dropdown_tari
Code:
<select name="tari">
<option value="0">- Tari -</option>
    &lt;?php foreach($tari as $tara) : ?&gt;
        <option value="&lt;?php echo $tara->idtara; ?&gt;">&lt;?php echo $tara->numetara; ?&gt;</option>
    &lt;?php endforeach; ?&gt;
</select>

In view view_dropdown

Code:
<select name="orase">
<option value="0">- Orase -</option>
    &lt;?php foreach($orase as $oras) : ?&gt;
        <option value="&lt;?php echo $oras->idoras; ?&gt;">&lt;?php echo $oras->numeoras; ?&gt;</option>
    &lt;?php endforeach; ?&gt;
</select>


Please, a helping hand
#3

[eluser]Twisted1919[/eluser]
Code:
<select name="selectcategorii" id="selectcategorii">
<option value="">- Selecteaza o categorie -</option>
&lt;?php foreach($categorii as $categorie) : ?&gt;
<option value="&lt;?php echo $categorie->idcategorie; ?&gt;">&lt;?php echo $categorie->numecategorie; ?&gt;</option>
&lt;?php endforeach; ?&gt;
</select>
//
<select name="selecttari" id="selecttari">
&lt;?php $tari_toate=$this->Cautare_model->getAlltariC(); ?&gt;
<option value="">- Alege o tara -</option>
&lt;?php foreach($tari_toate as $tara_toate) : ?&gt;
<option value="&lt;?php echo $tara_toate->idtara; ?&gt;">&lt;?php echo $tara_toate->numetara; ?&gt;</option>
&lt;?php endforeach; ?&gt;
</select>

//
<select name="selectorase" id="selectorase">
<option value="">- Alege un oras -</option>
&lt;?php $orase_toate=$this->Cautare_model->getAllOrasetoateC(); ?&gt;
&lt;?php foreach($orase_toate as $oras_toate) : ?&gt;
<option value="&lt;?php echo $oras_toate->idoras; ?&gt;">&lt;?php echo $oras_toate->numeoras; ?&gt;</option>
&lt;?php endforeach; ?&gt;
</select>


Code:
//Codul javascript pentru ce e mai sus
$(document).ready(function(){

    $('#selectcategorii').change(function() {
        $.ajax({
          type: "POST",
          url: "&lt;?= base_url();?&gt;cautare/arata_tari/" ,
          data: "idcategorie="+$('#selectcategorii').val(),

          success: function(data){
            $('#selecttari').html(data);
          }
        });
    });  

    $('#selecttari').change(function() {
        $.ajax({
          type: "POST",
          url: "&lt;?= base_url();?&gt;cautare/arata_oras/" ,
          data: "idtara="+$('#selecttari').val(),
          success: function(data){
            $('#selectorase').html(data);
          }
        });
    });  

});

Code:
// codul php pentru tari, de aici in colo te descurci cu celelalte metode.
function arata_tari()
    {
        $this->load->model('Cautare_model');  
        $idcategorie = $this->input->post('idcategorie');
        $out = '';
        if($tari = $this->Cautare_model->gettaridincategorieC($idcategorie))
        {
            foreach($tari AS $tara)
            {
                $out.= '<option value="'.$tara->id.'">'.$tara->nume.'</option>';
            }
        }
        exit($out);
    }
#4

[eluser]mariuskmc[/eluser]
Multumesc,
functioneaza... mai face ceva ciudatenii dar studiez problema.

Quote:Thanks,
it works ... do something weird, but studying the problem.
#5

[eluser]Twisted1919[/eluser]
pai se tragea de la faptul ca pusesei in div.
nu e nevoie, cu jquery poti popula un select box la fel de simplu cum poti popula un div, dar e indicata metoda mea(deasemenea studiaza jquery live() cand ai ocazia)
P.S: nu ar trebui sa faci interogari in bd din view, poti face in controller si apoi sa pasezi variabila in view si vezi ca nu cureti datele ce vin din post, poti fii vulnerabil la xss foarte usor.
#6

[eluser]mariuskmc[/eluser]
Quote:stems from the fact that you put in div.
is not needed, with jquery you can populate a select box as simple as you can populate a div, but it indicated my method (also studying jquery live () when you get a chance)

PS: you should not do the query database in the view, you can do in the controller and then pass the variable in view and not see that coming clean data from the post, you can very easily be vulnerable to XSS.

cautarea / formularul asta va fi pe toate paginile...
momentan nu am gasit alta varianta de a include rezultatele fara sa ma repet.

voi face inainte de afisarea rezultatelor o validare a formularului

Quote:search / form will be available on all pages ...
I have not found yet another solution to include the results without having to repeat myself.

I will do a validation form before displaying the results
#7

[eluser]Twisted1919[/eluser]
Fa o librarie si pune tot acolo apoi incarc-o global.
Dupa incarcarea globala, tot ce trebuie sa faci e ceva genul :
$tari = $this->libraria_mea->tari($categ_id);
Sau, extinde Controller cu un MY_Controller si pune codul global acolo, ai atatea variante .

Dar cred ca libraria ar fii cea mai buna solutie.
#8

[eluser]Cesar Kohl[/eluser]
www.romenia.com, english please.
#9

[eluser]mariuskmc[/eluser]
[quote author="Twisted1919" date="1292103798"]Fa o librarie si pune tot acolo apoi incarc-o global.
Dupa incarcarea globala, tot ce trebuie sa faci e ceva genul :
$tari = $this->libraria_mea->tari($categ_id);
Sau, extinde Controller cu un MY_Controller si pune codul global acolo, ai atatea variante .

Dar cred ca libraria ar fii cea mai buna solutie.
[/quote]

Quote:Do a library and put everything there and then upload it globally.
After filling of global, all you have to do is something like:
$tari = $this->libraria_mea->tari($categ_id);
Or, extend and make MY_Controller Controller with a global code there, you have many choices.

But I think the library would be the best solution.




Theme © iAndrew 2016 - Forum software by © MyBB