Undefined offsets on posted form using an array 
Author Message
 Undefined offsets on posted form using an array

I have a form which contains input fields in array format like this:

<input type="password" name="form[password]" size="10" value="<?php if
(isSet ($form['password'])) {echo $form['password'];} ?>" />

As there are several elements in the form, I am using the name
form[element] for each, where element is the name of that element. This
results in a single array being posted, rather than a messy set of
variables.

At the start of the processing part of the script, I have the line:

if (isSet($_POST['form'])) {$form = $_POST['form'];} else {$form = '';}

which converts $_POST['form'] to $form , as the items (now) in $form are
needed several times later in the script.

However, the output for the section results in
echo $form['password'];
being substituted with
"Notice:  Uninitialized string offset:  0 in [url]"
, even before it has been posted.

I find it curious than an offset warning should be generated given that
I'm explicitly using if(isSet ($form['password']))

I'm using PHP4.3.1 on Win2K/Apache1.3.27 and have set error_reporting
switched on fully, i.e. at level 2047. I would not regard setting
error_reporting to a lower level (or switching off display_errors!) as a
solution..

Can anyone see why this problem is arising?

Martin Lucas-Smith                              www.geog.cam.ac.uk/~mvl22
                                                www.lucas-smith.co.uk

Senior Computing Technician (Web Technician)
Department of Geography, University of Cambridge           (01223 3)33390

& Webmaster, SPRI
Scott Polar Research Institute, University of Cambridge



Sat, 05 Nov 2005 00:05:00 GMT  
 Undefined offsets on posted form using an array
hi martin,

Martin Lucas-Smith was scribbeling:

Quote:
> name="form[password]"

i don't really know, but it seems like you're mixing things.

to have form-elements in an array, use: somefield[] in the form.

if you need an array of all posted data, simply use $_POST, as this _is_
an array...

hth andreas

($form=$_POST)
--
collect xul annotations: http://xul.andreashalter.ch/



Sat, 05 Nov 2005 14:47:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. using python to post to a HTML form

2. CGI forms using POST method and Absoft Fortran on Linux

3. using TCL script for CGI, handling FORM POST method

4. using urllib or httplib to post with ENCTYPE=mulitpart/form-data

5. 'post' form without form

6. HTTP multipart/form-data form post

7. Problem extracting array-indexed form data (using HTTP_POST_VARS)

8. Form posting problem and post data issue

9. convert 2d array to 1d array without using shift registers and build array

10. offset offset??

11. structure array offsets

12. structure array offsets

 

 
Powered by phpBB® Forum Software