You are here: Re: Traversing $_REQUEST array and excluding items « PHP Programming Language « IT news, forums, messages
Re: Traversing $_REQUEST array and excluding items

Posted by Rami Elomaa on 05/30/07 07:12

Fred!head kirjoitti:
> Hi,
>
> Probably this is a newbie question so I appreciate you bearing with
> me.
>
> I've got an application where users can create forms with name= values
> they define. I'd like to write a script that traverses the $_REQUEST
> array to pull out each form value and put it into a simple comma-
> delimited feed they can then download as a CSV file. However, I see
> the $_REQUEST array is junked up with lots of form values, some I've
> heard of (PHPSESSID) and other mystery keys (e.g. dbx-pagemeta,
> __utmz).
>
> My question: how do I programmatically avoid these junk values so they
> don't wind up in my feed? Can I create and maintain an array of these
> junk keys then use that array as a filter to sort out only the
> $_REQUEST keys/values that are different? I tried array_diff() and
> array_intersect() but neither gave me the results I wanted. And using
> a long set of conditional operators (e.g. || and XOR) worked only if I
> had 2-3 conditions; more than that let in every $_REQUEST key/value
> pair.
>
> Any ideas how to do this in a way that lets my users have the
> flexibility of naming their form fields?
>
> Thanks in advance for any help and/or insight!

Don't use $_REQUEST, but $_POST instead. $_REQUEST is usually littered
with extra variables as you've noticed. $_POST and $_GET I think should
be better.

One thing you could do is put all the form fields in the same array:
<form method="post" action="">
<input type="text" name="my_cvs[field1]" />
<input type="text" name="my_cvs[field2]" />
<input type="text" name="my_cvs[field3]" />
....
<input type="text" name="my_cvs[fieldN]" />

<input type="submit" name="submit">
</form>

And then use $_POST['my_cvs'] instead of the entire $_POST, that way you
can be sure you get only the fields you wanted.

--
Rami.Elomaa@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация