![]() |
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. |
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 |
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[0] = "one"; $result[1] = "two"; $result[2] = "three"; $result[3] = "four"; |
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 |
Quote:
|
Oops, just realized I misread the question. Looks like you got the answer needed though
|
All times are GMT -8. The time now is 10:54 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project