vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   cycle through various POST array variables and types (https://vborg.vbsupport.ru/showthread.php?t=56036)

AmericanWoman 08-09-2003 04:17 AM

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? :)

g-force2k2 08-09-2003 10:39 PM

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

AmericanWoman 08-09-2003 10:44 PM

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. :)

g-force2k2 08-09-2003 10:51 PM

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

AmericanWoman 08-09-2003 11:56 PM

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).

g-force2k2 08-10-2003 12:03 AM

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

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

regards,
g-force2k2

AmericanWoman 08-10-2003 12:05 AM

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

g-force2k2 08-10-2003 12:12 AM

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

AmericanWoman 08-10-2003 12:14 AM

? 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. :(

g-force2k2 08-10-2003 12:19 AM

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


All times are GMT. The time now is 10:57 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01100 seconds
  • Memory Usage 1,756KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete