Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 03-09-2006, 11:57 AM
LWillmann LWillmann is offline
 
Join Date: Jan 2006
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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:
foreach ($read as $key => $data)
{
    if (
$key == 'bodyart')
        
$bodyart explode(", "$data);

Then in my template I have a series of checkboxes, here is one for example:

HTML Code:
<input type="checkbox" name="bodyart[]" value="Pierced tongue" 
<if condition="in_array('Pierced tongue', $bodyart)">checked</if> 
/>
This is attempting to see if the value for this checkbox is in the bodyart array, and if it is, then print checked so the box is checked.

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
In my source file for the page, I have declared $bodyart as global and as an array, but it still gives me the error.

PHP Code:
global $bodyart;
$bodyart = array(); 
If I click continue and go on and save the template, and load the page, it shows the proper box checked. So technically it works. But how do I keep from getting this warning on my template for each instance of that array?
Reply With Quote
  #2  
Old 03-09-2006, 12:03 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by LWillmann
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:
foreach ($read as $key => $data)
{
    if (
$key == 'bodyart')
        
$bodyart explode(", "$data);

Then in my template I have a series of checkboxes, here is one for example:

HTML Code:
<input type="checkbox" name="bodyary[]" value="Pierced tongue" 
<if condition="in_array('Pierced tongue', $bodyart)">checked</if> 
/>
This is attempting to see if the value for this checkbox is in the bodyart array, and if it is, then print checked so the box is checked.

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
In my source file for the page, I have declared $bodyart as global and as an array, but it still gives me the error.

PHP Code:
global $bodyart;
$bodyart = array(); 
If I click continue and go on and save the template, and load the page, it shows the proper box checked. So technically it works. But how do I keep from getting this warning on my template for each instance of that array?
Not sure whats wrong with your php

but your html should be checked="checked"
Reply With Quote
  #3  
Old 03-09-2006, 12:33 PM
Princeton's Avatar
Princeton Princeton is offline
 
Join Date: Nov 2001
Location: Vineland, NJ
Posts: 6,693
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

have you tried adding:
HTML Code:
<input type="checkbox" name="bodyary[]" value="Pierced tongue"<if condition="in_array('Pierced tongue', $bodyart)"> checked="checked"</if> />
on another template? (just to see if it allows you to save it)

if it goes thru .. it's something else on your template
Reply With Quote
  #4  
Old 03-09-2006, 12:38 PM
LWillmann LWillmann is offline
 
Join Date: Jan 2006
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #5  
Old 03-09-2006, 01:24 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you do an implode, the result i a string, not an array.
Reply With Quote
  #6  
Old 03-09-2006, 03:23 PM
LWillmann LWillmann is offline
 
Join Date: Jan 2006
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I do an explode when I read the data to turn it back into an array. You should see it in the code above.
Reply With Quote
  #7  
Old 03-13-2006, 07:11 PM
LWillmann LWillmann is offline
 
Join Date: Jan 2006
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

anyone else have an idea?
Reply With Quote
  #8  
Old 03-13-2006, 08:32 PM
merk merk is offline
 
Join Date: Nov 2001
Location: Canberra, Australia
Posts: 601
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 03-13-2006, 09:05 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried using a different name for that array since you've used bodyart for the name of the input field as well.
Reply With Quote
  #10  
Old 03-15-2006, 01:38 PM
LWillmann LWillmann is offline
 
Join Date: Jan 2006
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
eval('$navbar = "' fetch_template('navbar') . '";');
$bob = array();
$bob[]="testing";
eval(
'print_output("' fetch_template('FORUMHOME') . '");'); 
then I edited the FORUMHOME template and added the conditional line below:
HTML Code:
<if condition="in_array('testing',$bob)"><!-- It is there --></if>
Quote:
When I attempted to save the template, I get this:
The following error occurred when attempting to evaluate this template:

Warning: in_array(): Wrong datatype for second argument in /includes/adminfunctions_template.php(3537) : eval()'d code on line 14

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
If I click continue and save the template anyway, it saves just fine, if I reload the forum home page, I see my comment in the source. So I know that it's reading the array properly.

There MUST be a way to declare custom arrays and have the template system not error out.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:34 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02501 seconds
  • Memory Usage 2,270KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (4)bbcode_html
  • (5)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete