Re: Comparing string to array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Davey wrote:
Hi Stut,

Tuesday, June 19, 2007, 12:09:12 PM, you wrote:

If you have no control over what the fields in the form will be, what are you doing with the data? Surely if you're writing logic that requires you to know what the fields are called, you need to have control over it.

Here, this should help expand it further:

$icecream = $form->addSelectList('list', "icecream[flavor][]", 1, true, 'xml', 'icecream.xml', '//flavour');

The above code will add a select list into the current form (the
contents of which come from the icecream.xml file, using the xpath
query at the end, but this isn't relevant to the problem)

The 2nd parameter is the form name. In this instance the flavors from
the multi-select list will come into $_POST in: icecream[flavor]

When the form is submitted I take all of these form elements, and if
they exist in the filtered $_POST array, I re-populate them on error.

If the input name is just 'icecream' then you can do a simple:

if (isset($_POST[$input_name]))

.. and get the submitted value back.

If the input name is 'icecream[flavor][]' the above will no longer
work.

The problem is finding a way to expand the input name (which is a
string) into a format that $_POST can be searched for. Or do the
reverse, iterate through $_POST to find a match for the input name and
get that value.

Try this overly commented snippet on for size...

http://dev.stut.net/php/davey.php

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux