Frage

I have a situation where I'd like to post two values to a search query string array from a single checkbox. Because of the design, I can't just add another checkbox. The checkbox in question looks like so:

<input name="wpp_search[property_type][]" value="rental_home" type="checkbox" id="choice_c"/>
<label for="choice_c">For Rent</label>

what I now get in the query string is ...

{url}?wpp_search[property_type][0]=rental_home 

but what I need is to tie two values to that one check so I end up with this:

{url}?wpp_search[property_type][0]=rental_home&wpp_search[property_type][1]=building

Any simple solutions? There is only one other checkbox that already feeds that array, so I could force this one to be

{url}?wpp_search[property_type][0]=rental_home&wpp_search[property_type][2]=building
War es hilfreich?

Lösung

Generally it's not possible to send one value as two values.

One way I could imagine is that you reconfigure the ini-setting of arg_separator.input:

arg_separator.input = ";&"

This will allow you to use ; as well to separate values which then would allow you to inject the second value per that value:

<input name="wpp_search[property_type][0]" 
       value="rental_home;wpp_search[property_type][1]=building"
       ...
/>

If you make use of the value ; in other form values you naturally need to properly escape them to make this compatible.

Another way is that you insert a hidden field with that value and if your checkbox is checked, you change the name of it to the right name. If unchecked, you change the name of it back to something not right:

<input type="hidden" name="---wpp_search[property_type][1]" value="=building" />

Take the javascript reference of your choice and do the needed DOM manipulation on click of the other checkbox to remove the three --- at the beginning of the name.

Andere Tipps

You can seperate values with for example "|" like this value="value1|value2". Then later you can use the function explode: $p = explode("|", $value); and you get 2 values.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top