php-general Digest 7 Jun 2012 15:15:47 -0000 Issue 7844
Topics (messages 318177 through 318178):
Re: Read dynamic variable from HTML form into PHP
318177 by: Jim Giner
A Question of SESSION
318178 by: Tedd Sperling
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
"Maciek Sokolewicz" <maciek.sokolew...@gmail.com> wrote in message
news:4fcf23af.7040...@php.net...
> On 06-06-2012 05:11, Jim Giner wrote:
>> "Govinda"<govinda.webdnat...@gmail.com> wrote in message
>> news:72497398-3a6c-4faa-89f2-565c18fd2...@gmail.com...
>>
>> On 2012-06-05, at 10:54 PM, Devangnp wrote:
>>
>>> 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.
>>>
>>
>>>>> 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,
>>>>> Devang
>>>>
>>>>
>>>> http://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
>>
>>
>> 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.
>>
>>
>
> 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' => [
> 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
Thank you Tul for your eloquent post. Now I understand how to handle those
kinds of "array" inputs myself!
And - I do think from his vague description that the OP is looking for this
kind of help. If not, then it was REALLY vague!
--- End Message ---
--- Begin Message ---
Hi Daniel and gang:
Considering I'm never afraid to show my ignorance, please review the following
example.
Because of the way I normally use sessions and considering this way works for
me, I thought I knew what sessions were about -- but my faith is eroding.
Cases in point
1. The following is the way I normally use sessions (with COOKIES turned ON):
http://www.webbytedd.com/b/sessions
It works.
2. Considering that people may have their COOKIES turned OFF, I tried this:
http://www.webbytedd.com/b/sessions1/
It works when COOKIES are turned ON, but the SID does not appear in the URL --
I find that odd.
However, if COOKIES are turned OFF, then SID does appear in the URL, but the
process of passing session variables doesn't work -- I find that confusing.
What's the point of passing the SID if it isn't going to be used?
3. Looking for an explanation, I came across Daniel's post to the PHP manual,
which follows:
http://www.webbytedd.com/b/sessions3
Now I am totally bonkers.
What am I not getting?
Cheers,
tedd
____________________
t...@sperling.com
http://sperling.com
--- End Message ---