Re: Variables - Using The Contents Of A Varibale Name Built Dynamically
| From: | Michael Davey | Date: | Sat, 01 Jun 2002 11:33:52 +0000 |
| Subject: | Re: Variables - Using The Contents Of A Varibale Name Built Dynamically | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-100216@lists.php.net to get a copy of this message | ||
You could give the button the same name in each form - only the fields in
between the <form</form> tags is actually submitted, then put a hidden field
in the form that uniquely identifies the data being submitted.
Just a thought... it is what I usually do...
Mikey
"Jason Teagle" <jason@teagster.co.uk> wrote in message
news:20020601092017.9040.qmail@pb1.pair.com...
> I have found an alternate way of achieving what I want, but I'm wondering
if
> there was an easier way. I have a PHP file that builds a Web page that
> includes forms. The forms are built dynamically based on the contents of a
> file, and thus there may be one or two or more forms on the page at any
> time. This means that I have controls named $btnChoice1 (first form),
> $btnChoice2 (second form), etc. (radio buttons). All of these forms are of
a
> similar format, and so lead to the same PHP page in their action - a
> parameter is passed in the URL to identify which form it came from.
>
> When the form passes to its action file, another PHP file, there are two
> ways to get form data: $_POST["control_name"] or $control_name. The
problem
> is, the control name I need has to be built dynamically based on which
form
> it came from. So I need this:
>
> $btnName = "btnChoice" . $form_number ;
>
> But now I have the tricky bit - $_POST[$btnName] doesn't work because it
> requires nested substitution of variables, and similarly I can't echo
> $btnName because that will of course use "btnChoice2" instead of the
> _contents_ of the control named btnChoice2.
>
> Is it possible to 'dereference' (whatever the term is) the variable name
> twice? I tried
>
> $$btnName
>
> in the stupid hope that it would first interpret that to
>
> $btnChoice2
>
> and then interpret that to the contents of the control, but of course it
> failed.
>
> I ended up using foreach on $_POST to pull out control names and their
> contents, and comparing the control name to my built-up name - but I was
> wondering if there's a more elegant way of doing what I wanted?
>
> Promise my next question to the group will be short {:v)
>
>
> --
> --------------------------------------------
> _ _
> o o Jason Teagle
> < jason@teagster.co.uk
> v
> --------------------------------------------
>
>