07-12-2005, 07:36 AM | #1 (permalink) |
Addict
Location: USA
|
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.
__________________
Having Girl Problems? |
07-12-2005, 08:49 AM | #2 (permalink) |
Insane
Location: West Virginia
|
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
__________________
- Artsemis ~~~~~~~~~~~~~~~~~~~~ There are two keys to being the best: 1.) Never tell everything you know |
07-12-2005, 02:10 PM | #3 (permalink) |
Darth Papa
Location: Yonder
|
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); $result[0] = "one"; $result[1] = "two"; $result[2] = "three"; $result[3] = "four"; |
07-12-2005, 03:14 PM | #4 (permalink) |
Tilted
Location: Calgary, AB
|
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
__________________
As soon as you stop living, you start dying.... |
Tags |
form, html, multiple, php, single, variables |
|
|