How to have unique id's for POSTing when displaying many table rows?

This is a discussion on How to have unique id's for POSTing when displaying many table rows? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; How to deal with multiple records and posting values? (I'm fairly new to html/php etc. so maybe there ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-18-2005
Second_Chance
 
Posts: n/a
Default How to have unique id's for POSTing when displaying many table rows?

How to deal with multiple records and posting values?
(I'm fairly new to html/php etc. so maybe there is a simple answer?

I have a page showing several records - each table record is contained
within a separate form and has action buttons that submit (for
update/delete etc).

I generate the html using a php loop, which adds the loop counter to
inputs name and id (to ensure unique id's).
This results in the $_POST array receiving results as "budgetname1", or
"budgetname2" etc.

Do I have to parse the POST array, when what i really want is just
"budgetname" in the POST array, no matter which record the user clicks
on (the values tell me what i need!).
Although the page works if I assign the same id's in each form, the HTML
spec seems to suggest that a) id's must be unique in the document, b)
that name and id must be the same, and c) that "[]" characters are not
permitted in HTML 4.01

So do I have to step thru the POST array checking all the keys looking
for a substring match of the key to "budgetname%" or similar??

I guess this must be a common problem with multi-row tables on a page,
but what's the best solution?
thanks
chris
Reply With Quote
  #2 (permalink)  
Old 05-18-2005
Oli Filth
 
Posts: n/a
Default Re: How to have unique id's for POSTing when displaying many table rows?

Second_Chance wrote:
> I have a page showing several records - each table record is

contained
> within a separate form and has action buttons that submit (for
> update/delete etc).
>
> I generate the html using a php loop, which adds the loop counter to
> inputs name and id (to ensure unique id's).
> This results in the $_POST array receiving results as "budgetname1",

or
> "budgetname2" etc.
>
> Do I have to parse the POST array, when what i really want is just
> "budgetname" in the POST array, no matter which record the user

clicks
> on (the values tell me what i need!).
> Although the page works if I assign the same id's in each form, the

HTML
> spec seems to suggest that a) id's must be unique in the document


id attributes of HTML controls don't affect the POST variable name,
only the name attribute. So just make all the name attributes the same.

> b) that name and id must be the same


Where does it say that??

> and c) that "[]" characters are not permitted in HTML 4.01


And where does it say that?
Using [0], [1], [2], etc. is the recommended way of getting an array as
a POST variable in PHP.

--
Oli

Reply With Quote
  #3 (permalink)  
Old 05-18-2005
Second_Chance
 
Posts: n/a
Default Re: How to have unique id's for POSTing when displaying many tablerows?

Oli Filth wrote:

> Second_Chance wrote:
>
>>I have a page showing several records - each table record is

>
> contained
>
>>within a separate form and has action buttons that submit (for
>>update/delete etc).
>>
>>I generate the html using a php loop, which adds the loop counter to
>>inputs name and id (to ensure unique id's).
>>This results in the $_POST array receiving results as "budgetname1",

>
> or
>
>>"budgetname2" etc.
>>
>>Do I have to parse the POST array, when what i really want is just
>>"budgetname" in the POST array, no matter which record the user

>
> clicks
>
>>on (the values tell me what i need!).
>>Although the page works if I assign the same id's in each form, the

>
> HTML
>
>>spec seems to suggest that a) id's must be unique in the document

>
>
> id attributes of HTML controls don't affect the POST variable name,
> only the name attribute. So just make all the name attributes the same.
>
>
>>b) that name and id must be the same

>
>
> Where does it say that??
>
> > and c) that "[]" characters are not permitted in HTML 4.01

>
> And where does it say that?
> Using [0], [1], [2], etc. is the recommended way of getting an array as
> a POST variable in PHP.
>


Oli, thanks for reply..

re c) I read the following at:

http://www.w3.org/TR/html4/types.html#type-id
"ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods ("."). "

from which I assume [] are not ok

re b) that name and id must be the same

I can't find the section, think was in the same spec.. and said that if
both name and id attributes are set they should be the same (and name
was now deprecated..)
the last bit is here:
from this page:

www.w3.org/TR/html4/interact/forms/html#h-17.1

name = cdata [CI]
This attribute names the element so that it may be referred to from
style sheets or scripts. Note. This attribute has been included for
backwards compatibility. Applications should use the id attribute to
identify elements.

However, I am quite new at this, so will follow your suggestions
many thanks
Chris

Reply With Quote
  #4 (permalink)  
Old 05-18-2005
Oli Filth
 
Posts: n/a
Default Re: How to have unique id's for POSTing when displaying many table rows?

Second_Chance wrote:
> Oli Filth wrote:

<...SNIP...>

> Oli, thanks for reply..
>
> re c) I read the following at:
>
> http://www.w3.org/TR/html4/types.html#type-id
> "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
> followed by any number of letters, digits ([0-9]), hyphens ("-"),
> underscores ("_"), colons (":"), and periods ("."). "
>
> from which I assume [] are not ok


Hmm, you're absolutely right, it does say that, I'd never noticed that
before! Which is bizarre, cos the HTML validator has never complained!

>
> re b) that name and id must be the same
>
> I can't find the section, think was in the same spec.. and said that

if
> both name and id attributes are set they should be the same (and name


> was now deprecated..)
> the last bit is here:
> from this page:
>
> www.w3.org/TR/html4/interact/forms/html#h-17.1
>
> name = cdata [CI]
> This attribute names the element so that it may be referred to from
> style sheets or scripts. Note. This attribute has been included for
> backwards compatibility. Applications should use the id attribute to
> identify elements.


That's referring to the name attribute for the <FORM> element, not the
individual <INPUT>, <TEXTAREA> and <SELECT> controls within it.

--
Oli

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:23 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0