Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2003, 04:17 AM
AmericanWoman AmericanWoman is offline
 
Join Date: Jan 2002
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default cycle through various POST array variables and types

I know I remember this from way back when, but I need to find some code that cycles through all the variables of a POST array...and if the variable is, itself, an array, it splits it into its individual values.

For instance, my config screen has a multiple select box, in addition to several regular text boxes, etc. While the text boxes will return a single value, the select box returns an array. I'm hoping to find some simple code to cycle through both types, and output the name/value pairs to a querystring.

Any ideas?
Reply With Quote
  #2  
Old 08-09-2003, 10:39 PM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

if you're reffering to the HTTP_POST_VARS then you can cycle through them:

PHP Code:
while( list( $key$val ) = each$HTTP_POST_VARS )  )
{
    echo 
"<b>" $key ":</b>" $val "<br>";

it will print out each of the post names with their values...

and you can adjust the script to get the effect you're looking for...

regards,
g-force2k2
Reply With Quote
  #3  
Old 08-09-2003, 10:44 PM
AmericanWoman AmericanWoman is offline
 
Join Date: Jan 2002
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You rock, thank you. I can then extrapolate the same function for finding out whether the key holds an array, I would think, like so:

PHP Code:
if (is_array($HTTP_POST_VARS['$key']))  {
 do 
the same while function
  } 
I'll let you guys know how it comes out. The result of all this stuff may be my first hack. :P Here's hoping!

Thanks. I'm an ass. Should have known.
Reply With Quote
  #4  
Old 08-09-2003, 10:51 PM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well the actual array values are seperated into their respected values...

if you're trying to get the array of values and search though them then i think this is what you should use...

for instance for an input value to be an array it would require the name to be

Code:
<input type="text" name="varname[]" value="">
then after you submit the data you just do:

PHP Code:
while( list( $key$val )  = each$varname ) )
{
   echo 
"<b>" $key ":</b> " $val "<br>";

i think this is the best way to get arrays from your data, pretty much your data will only be an array if you dictate it to be in the input values...

regards,
g-force2k2
Reply With Quote
  #5  
Old 08-09-2003, 11:56 PM
AmericanWoman AmericanWoman is offline
 
Join Date: Jan 2002
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not searching through the array; I'm outputting all the values passed.

The script to parse ALL the post vars worked fantastic, but I ran into a problem trying to handle post arrays. Here's the code:

PHP Code:
if (isset($submit))    {
    
$scriptmid "?foo=bar";
    while (list(
$key,$value) = each($POST_VARS))    {
        
//echo "Starting POST var loop.";
        
if ($key <> "submit" && $key <> "thecode")    {
            if (
is_array($key))    {
                
//echo "POST var is array - starting loop.";
                
$scriptmid $scriptmid "&" $key "=[";
                while (list(
$pkey,$pvalue) = each($key))    {
                    
$scriptmid $scriptmid $pvalue ",";
                }
                
$scriptmid $scriptmid "]";
            }
            else    {
                
$scriptmid $scriptmid "&" $key "=" $value;
            }
        }
    }

It recognizes that the one field I'm looking for is an array, but it doesn't output the right information from the array handling loop.

For what I'm trying to do, take a look at the following:

www.acuraworld.com/forums/jsconfig.php

The script is being used to output a customized syndicated content feed. All the other vars are working fine, but I'm not having any luck passing forumid (look at the script tag in the textarea at the bottom of the screen after you've selected a couple of forums).
Reply With Quote
  #6  
Old 08-10-2003, 12:03 AM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ah didn't know you were using a multiple select form

so thats the array that you're trying to get the data for yes? ( which represent the forumids )

regards,
g-force2k2
Reply With Quote
  #7  
Old 08-10-2003, 12:05 AM
AmericanWoman AmericanWoman is offline
 
Join Date: Jan 2002
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah - as you can see from the script tag it outputs, it just says "forumid=Array"...even though, when I uncomment my loop statements for debugging, it IS entering the is_array loop structure.

I don't get it! I'm very close to having this thing done, and I really wish it would work, already! :P
Reply With Quote
  #8  
Old 08-10-2003, 12:12 AM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yes well looking at the code no matter how many ones you select the form will only return one id on a multiple select that i was just testing... any ideas on how to get all of the values that are selected?

g-force2k2
Reply With Quote
  #9  
Old 08-10-2003, 12:14 AM
AmericanWoman AmericanWoman is offline
 
Join Date: Jan 2002
Posts: 47
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

? The code output at the top that says "Option ## selected" shows you the multiple options passed...? This same type of loop is generating that output, except the post variable name I'm looking for is specified instead of inferred.

Works fine on my end, as far as passing multiple values goes. It's just getting them to display that's the problem.
Reply With Quote
  #10  
Old 08-10-2003, 12:19 AM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

okay my bad i got the array to pass as well, but what do you mean you can get them to display?

when i submit it says what options are selected but what effect were you trying to achieve?

err... nvm i see the string that you're trying to make but is that the problem that its not coming out as you wanted it to?

g-force2k2
Reply With Quote
Reply


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 09:22 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.04446 seconds
  • Memory Usage 2,268KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_code
  • (4)bbcode_php
  • (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_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