Re: Read dynamic variable from HTML form into PHP
| From: | Maciek Sokolewicz | Date: | Wed, 06 Jun 2012 09:32:31 +0000 |
| Subject: | Re: Read dynamic variable from HTML form into PHP | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318176@lists.php.net to get a copy of this message | ||
On 06-06-2012 05:11, Jim Giner wrote:
"Govinda"<govinda.webdnatalk@gmail.com> wrote in message news:72497398-3A6C-4FAA-89F2-565C18FD2156@gmail.com... On 2012-06-05, at 10:54 PM, Devangnp wrote:A possible answer to a possible question that he might have (yes, the question is very vaguely described, as Govinda already explained) would be the following: Assuming you have an HTML form, which may contain a variable number of fields, you want to somehow access their passed-through values in PHP without prior knowledge of the exact number of those fields. There are essentially 2 ways: 1. All POSTed data is present in the $_POST superglobal array. So you could just loop over that, ignore the fields you already knew were there, and the data remaining is then essentially the data you seek. The keys in the $_POST array are the fieldnames you are looking for. 2. There's a special trick in PHP, when you name a field "name[]" in HTML and then POST it to a PHP script, it will turn into an array field. So <input name="a[]" value="1"> <input name="a[]" value="2"> will then end up in: $_POST = [ 'a' => [I know how to pass variable but having difficulties when I use the dynamic form field in HTML that add more boxes as per user require.Devang, Please keep replies on-list. Please post your replies at the bottom, past the older (snipped) content. Many here will be glad to help.. but you'll need to make your question more clear.. at least for me to be able to help anyway. First of all, what do you mean exactly, by, "the dynamic form field in HTML"? And by "boxes" do you mean form inputs of 'text' type? If so, then do you mean to suggest that input by the end user should determine the number of text inputs that should display in a second HTML form? Please spend more time describing what you are trying to do.. and also please show any code you attempt(ed) to accomplish this. If you are unable to write any code, then try pseudo code - meaning write in successive lines of prose what you want code to do, and post that here. -Govinda= I thought he meant previously generated "array" type fields, that use the same name. I've never done it myself, but I thought the method of handling this kind of input included placing a hidden field with the count on the form to be retriieved later and used in processing the dynamic fields in a loop.Hi All, I am a basic user of PHP and I have need of reading the dynamic HTML form field as a variable in PHP so it will be great if someone can share some good link or snip for quick understanding. Thanks, Devanghttp://lmgtfy.com/?q=how+to+pass+and+receive+a+PHP+variable When just starting out, "Google is your friend". Or did I misunderstand your question? -Govinda
0 => '1',
1 => '2'
]
]
If you had not added the square-brackets, you would have:
<input name="a" value="1"> <input name="a" value="2"> ending up in:
$_POST = [
'a' => '2'
]
Thus not ever seeing the value '1'.
I hope this answers part of your question; and if not, PLEASE explain in more detail what your problem is, what you tried, why it didn't work, and what you want to know exactly. Your current question is very very short and vague enough to easily cause misunderstanding.
- Tul