Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   Getting multiple PHP variables using a single HTML form (https://thetfp.com/tfp/tilted-technology/91871-getting-multiple-php-variables-using-single-html-form.html)

soma 07-12-2005 07:36 AM

Getting multiple PHP variables using a single HTML form
 
I'm working on a small personal stock research tool, and I want to know if it is possible to get multiple php variable values from 1 html form. I'll try to better explain exactly what I mean:

Let's say I have a list of 5 stock symbols, each separated by a single space:

amd intc msft nvda atyt

Now let's say I copy all of them, and paste them into an html form and press the submit button. From here, is it possible to separate each of the symbols and define a variable to each one?

If what I'm saying does not make sense, please ask.

Artsemis 07-12-2005 08:49 AM

Lets say your form field names are field1, field2, and field3...

You can do the following:
$newField1 = $_GET['field1'];
$newField2 = $_GET['field2'];
$newField3 = $_GET['field3'];

For a post, simply use $_POST. Another handy one is $_REQUEST which will grab the variable wether it be a POST, GET, or even COOKIE

ratbastid 07-12-2005 02:10 PM

I believe you're looking for the explode() function. It splits a string into an array on a specified string.

Code:

$data = "one two three four"
$result = array();
$result = explode(" ", $data);

The array $result now has the folowing values:

$result[0] = "one";
$result[1] = "two";
$result[2] = "three";
$result[3] = "four";

wdevauld 07-12-2005 03:14 PM

You can also set the names/id on your form to be array values:

<input name="field[0]" type="text" value="123.4"/>
<input name="field[1]" type="text" value="456.7"/>
<input name="field[2]" type="text" value="789.0"/>

--or if you don't care about which index --

<input name="field[]" type="text" value="123.4"/>
<input name="field[]" type="text" value="456.7"/>
<input name="field[]" type="text" value="789.0"/>


then when you $_GET['field'] you can use it as an array

theFez 07-12-2005 08:54 PM

Quote:

Originally Posted by wdevauld
then when you $_GET['field'] you can use it as an array

keep in mind, $_GET is an array and can be treated as such (accessed by index or looped).

Artsemis 07-13-2005 03:06 AM

Oops, just realized I misread the question. Looks like you got the answer needed though


All times are GMT -8. The time now is 01:50 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73