This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

jlongo
jlongo

Hi all

I have made a ajax search on frontend to mysql tables that is working fine till i decided to place some other options to the search. In this case i'm using radiobuttons to change the way that the seach is made (text or tags)... i have two radio buttons like this:

    <div class="btn-group btn-group-horizontal" data-toggle="buttons">
                <label class="btn active">
                    <input type="radio"
                           name='rdTipo'
                           data-request="onTipo"
                           checked
                           value="normal">
                    <i class="fa fa-circle-o"></i><i class="fa fa-dot-circle-o"></i> <span>Normal</span>
                </label>
                <label class="btn">
                    <input type="radio"
                           name='rdTipo'
                           data-request="onTipo"
                           value="etiqueta">
                    <i class="fa fa-circle-o"></i><i class="fa fa-dot-circle-o"></i><span>Etiquetas</span>
                </label>
            </div>

and in a php block when using request-data (i tryied on other event handler too)

       function onTipo(){
          $this['testeradio'] = input('rdTipo');
        }

And i can't get the values of the radio buttons using input('xxxx') and also testing with Input::all() on php block of the page with same result... In first i tried without the data-request as i have other on input text (and this one works fine) but with this option i can't get the values too...

Any help or ideia will be appreciated.

TIA

JL

Last updated

alxy
alxy

Both elements have the same handler name, so you can only submit one of them at a time. The solution you can use here is to surround your inputs by a <form>-tag and bind the handler to this form. This will send all the inputs within that form in the POST data carried with the request.

Last updated

jlongo
jlongo

Thanks for the sugestion alxy.

But with form i have a problem that is i want to change the options on the fly as user selects them and with form the user must have to submit the selection... well, maybe i can force the submit on events as onChange or onClick on radio buttons...

I do not understand why do not work as when you select one of the radiobuttons the value is assigned with the radiobutton rdTipo variable and i can confirm that with alert(document.querySelector('input[name="rdTipo"]:checked').value);. I get the values when selecting any of the radiobuttons... Also i can see the ajax request processing on any of the radiobuttons... Doing some more digging...

JL

jlongo
jlongo

Ok... the problem is that the $_POST['rdTipo'] don't persist between ajax calls and i'm not aware of that...

I solved that puting the value on session variable on event handler that is the same for both radiobuttons without problems. Also to get more control of what is passed i defined a variable on data-request-data="tipo: 'normal'" or 'etiqueta', but the rdTipo also works.

When i need the variable i get it with Session::get('key').

The code is something like:

   <div class="btn-group btn-group-horizontal" data-toggle="buttons">
                <label class="btn active">
                    <input type="radio"
                           name="rdTipo"
                           data-request="onTipo"
                           data-request-data="tipo: 'normal'"
                           checked
                           onchange="nojavascript...mostraEsconde('opcoesetiquetas')"
                           value="normal">
                    <i class="fa fa-circle-o"></i><i class="fa fa-dot-circle-o"></i> <span>Normal</span>
                </label>
                <label class="btn">
                    <input type="radio"
                           name="rdTipo"
                           data-request="onTipo"
                           data-request-data="tipo: 'etiqueta'"
                           onchange="nojavascript...mostraEsconde('opcoesetiquetas')"
                           value="etiqueta">
                    <i class="fa fa-circle-o"></i><i class="fa fa-dot-circle-o"></i><span>Etiquetas</span>
                </label>
            </div>

And the event handler

 function onTipo(){
    Session::put('tipo', $_POST['tipo']);
     }

Well, not sure if is the best choice... but works

[EDIT]

The 'onchange' attribute don't is needed... i use it to show/hide other div with other options dependeing on selected radiobutton

JL

Last updated

K.Singh
K.Singh

how to store all data in database comes from Input::all()

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.