NYCPHP Meetup

NYPHP.org

[nycphp-talk] accessing $_SESSION elements

Aaron Fischer agfische at email.smith.edu
Fri Oct 24 18:40:15 EDT 2003


Hi Robert,

I do have an array of data, let me backtrack to explain:
In the first form a user enters name, etc. and how many fairs they want 
to enter.
On post, a loop iterates set number of times which is equal to the 
number of fairs they have chosen.
On each iteration, the loop spits out the html form fields that enables 
the user to enter each fair, i.e. 1_fair_name, 1_fair_location, 
1_fair_date, 2_fair_name, 2_fair_location, 2_fair_date, etc.  The 1, 2, 
3, etc. distinguish each fair.  If I was creating a static html form I 
would be naming the fields with the same convention.  Here I am just 
using php to create the fields.

I did this to make the interface more appealing, so the user doesn't 
have to wade through a long form with all of the fields for 10 
different fairs if they only want to enter 1.

Then on submit I am looping the set number of times again and testing 
to see if the array elements are empty.  If any element is empty I will 
reload the form with appropriate error messages.

On typing this I realize that I don't need to test to see if array 
elements are there.  I know what is there, based on the number of fairs 
they have chosen, which is stored as an array element as well.  I just 
want to test to see if said fair elements are empty.

I have been reading through the array functions but hadn't found a good 
way to say "Does array key "foo" exist?  and if it does, is it empty?". 
  I could very well be blind at this point.

-Aaron

On Friday, October 24, 2003, at 05:57 pm, Robert Redcay wrote:

> Aaron,
> It seems like what you really want is an array of data. If you have 
> your form submit the individual fairs as elements of an array 
> ($fairs), you'll find php's array functions very helpful when 
> determining what indeces are set. It seems that your prepending an 
> integer to the string 'fair_name' is just a poor man's array which 
> makes your looping tests akward.
>
> Best,
> Robert Redcay




More information about the talk mailing list