vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Help needed... FORMS & PHP (not as noob as you think) (https://vborg.vbsupport.ru/showthread.php?t=78938)

Deaths 03-28-2005 10:09 AM

Help needed... FORMS & PHP (not as noob as you think)
 
Ok, here's my problem:

I'm currently using an XHTML form (duh), which sends some data to a PHP file.

Now, one of the text input boxes, looks like this:
HTML Code:

<input name="products[$order[productid]][quantity]" type="text" class="bginput" value="1" size="2">
Lets say $order[productid] is 1, so the name will be this:
HTML Code:

products[1][quantity]
Now, I was wondering how I can let PHP read that "1" (not static, but dynamic I mean. If it would be 2, it would read "2", if it would be "3" it would read "3".
I'm pretty sure this is possible, but I can't figure it out.

Help is appreciated, as always.

pie 03-28-2005 11:28 AM

I'd parse the $variable OUT of html personally.

Deaths 03-28-2005 11:56 AM

Yes, but doing it like this is a lot more effective (you would need to see the code to understand this, though)

Marco van Herwaarden 03-28-2005 09:03 PM

Try:
PHP Code:

foreach ($products AS $orderid=>$quantity)
{
  foreach (
$quantity AS $key=>$value)
  {
      ....
  }



Deaths 03-29-2005 06:28 AM

I don't get how I could get that "1" from products[1][quantity] with your code...

I've tried str_replace, but I would need to know the number already...

If it is possible with your code, could you maybe give an example?

Marco van Herwaarden 03-29-2005 06:34 AM

$products will hodl the '1'.

I already gave you an example.

Deaths 03-29-2005 06:46 AM

I believe you when you say it'll hold a 1, trust me ^^.

But the question is, how should I define products[1][quantity] with that code?
Should I globalize it, or just use the $_POST['products[1][quantity]']?

Marco van Herwaarden 03-29-2005 08:11 AM

You should globalize it, but using the $_POST would also work.

Deaths 03-29-2005 09:08 AM

Could you maybe give an example?
What I'm doing is this:
PHP Code:

globalize($_POST, array('products[1][quantity]'));
        foreach (
$products AS $orderid=>$quantity)
        {
              foreach (
$quantity AS $key=>$value)
                  {
                      echo 
"$products";
                  }
        } 

It then errors me out:
Code:

Warning: Invalid argument supplied for foreach() in /products.php on line 70
This is on line 70:
PHP Code:

foreach ($products AS $orderid=>$quantity


Marco van Herwaarden 03-29-2005 10:57 AM

PHP Code:

globalize($_POST, array('products')); 



All times are GMT. The time now is 01:32 PM.

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.01047 seconds
  • Memory Usage 1,733KB
  • 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
  • (2)bbcode_html_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete