The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Conditionals and in_array...
I have created a table, and in that table I have fields. Some of those fields store multiple values (a group of checkbox values). The selected items are stored in the fields as comma seperated strings (using PHP's implode).
I have created a page, and on that page, I have managed to get it to pull the data from that table. I run the resultset through a foreach loop to do some testing. PHP Code:
HTML Code:
<input type="checkbox" name="bodyart[]" value="Pierced tongue" <if condition="in_array('Pierced tongue', $bodyart)">checked</if> /> When I attempt to save the template in the ACP I get this message: Code:
Warning: in_array(): Wrong datatype for second argument in /includes/adminfunctions_template.php(3537) : eval()'d code on line 364 PHP Code:
|
#2
|
||||
|
||||
Quote:
but your html should be checked="checked" |
#3
|
||||
|
||||
have you tried adding:
HTML Code:
<input type="checkbox" name="bodyary[]" value="Pierced tongue"<if condition="in_array('Pierced tongue', $bodyart)"> checked="checked"</if> /> if it goes thru .. it's something else on your template |
#4
|
|||
|
|||
The problem started when I added the <if condition> to the template. Otherwise, the template saves just fine.
I fixed the checked="checked" thing, thanks for that! Oh, and fixed a typo above, $bodyary should be $bodyart |
#5
|
|||
|
|||
If you do an implode, the result i a string, not an array.
|
#6
|
|||
|
|||
I do an explode when I read the data to turn it back into an array. You should see it in the code above.
|
#7
|
|||
|
|||
anyone else have an idea?
|
#8
|
|||
|
|||
Because saving the template processes it to provide that warning, it isnt possible to do anything about it short of supressing the error.
Try @in_array(), other than that you'll have to live with it. |
#9
|
||||
|
||||
Have you tried using a different name for that array since you've used bodyart for the name of the input field as well.
|
#10
|
|||
|
|||
It has nothing to do with the field name, or the array name.
I did another test. I edited index.php in the forum root folder and added the $bob lines below: PHP Code:
HTML Code:
<if condition="in_array('testing',$bob)"><!-- It is there --></if> Quote:
There MUST be a way to declare custom arrays and have the template system not error out. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|