Categories > TinyButStrong general >

Setting HTML parameters based on array prescence

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: bsander
Date: 2006-08-01
Time: 16:22

Setting HTML parameters based on array prescence

I have a list of checkboxes and I want to check them according to a PHP array which contains some or all of the elements names. IS there an easy way in TBS to do this? I couldn't find it in the manual :(

Thanks!
By: Skrol29
Date: 2006-08-01
Time: 16:31

Re: Setting HTML parameters based on array prescence

Hi,

See the HTML plug-in.
By: bsander
Date: 2006-08-01
Time: 16:51

Re: Setting HTML parameters based on array prescence

Ah, I see. Thanks :)

I had to edit it a little to look for id instead of name, but it went allright. Might be nice to have as an option in there maybe, for the cases where it's needed..

Good stuff.
By: Skrol29
Date: 2006-08-01
Time: 17:06

Re: Setting HTML parameters based on array prescence

In an HTML page, IDs must be unique, while names can be repeated. For a group of option buttons, names must be repeated and IDs must unique. Thta's why  items to check should not be searched from their IDs but from there names.
By: bsander
Date: 2006-08-01
Time: 17:13

Re: Setting HTML parameters based on array prescence

I know, that's why I said it should be an option. In my case I needed the ID for a set of checkboxes, because the names where - as you say - the same (to put all checked items in a PHP array when posted). Had I used the name, all checkboxes would be checked/unchecked simultaneously.

I'll post the affected piece of code in case it's unclear:
<form>
    Zoek op:
    <input type="text" value="[var.vraag]"name="Zoek">
    <input type="submit" value="&gt;&gt;"><br>
    In:
    <input type="checkbox" id="titel" name="In[]" value="titel"><label for="titel">Titel</label>
    <input type="checkbox" id="schrijver" name="In[]" value="schrijver"><label for="schrijver">Schrijver</label>
    <input type="checkbox" id="beschrijving" name="In[]" value="beschrijving"><label for="beschrijving">Beschrijving</label>
    [var.velden;ope=html;select=titel][var.velden;ope=html;select=schrijver][var.velden;ope=html;select=beschrijving]
</form>
This would never work when using name as the selection criterium.
By: Skrol29
Date: 2006-08-01
Time: 17:36

Re: Setting HTML parameters based on array prescence

> Had I used the name, all checkboxes would be
> checked/unchecked simultaneously.

The following works fine with your form:
[var.velden;ope=html;select='In[]']

If $velden is an array containing selected values, like $_POST['In']
By: bsander
Date: 2006-08-01
Time: 17:39

Re: Setting HTML parameters based on array prescence

Really? I tried it but it didn't work here.. Though maybe I made a mistake, I'll check it out again tomorrow when I get back.
By: Skrol29
Date: 2006-08-01
Time: 17:41

Re: Setting HTML parameters based on array prescence

I've tested it with your snippet, it worked fine for me.