473,408 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How do I parse form elements or am I doing this wrong?

I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.

I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,

table areas
id 1 areaname beverages
id 2 areaname grill

table menuitems

id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger

Now, in my form, I have the entire menu displayed with all areas and
menu items. In each area there is small set of textboxes to enter new
menuitems for that area with a button. Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. I know
I've lost you. Let me try again.

In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. These are generated
by a set of loops from my database.

Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:

myprocessor.php?id=3&item=coke&id=4&item=0.... I just get a
querystring with lots of blank variables. I know I must be doing
something to have this. All I really need is one ID. The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. Thank you.
Sep 13 '08 #1
14 1780
hello

Why not make a <FORMfor every area? that way you will only get a set
of values for that area.

For instance <FORM for beveragesand <FORM for grilleach with a
separate SUBMIT button?

why not use the POST method instead of the GET?

Why not use a special ID for each field (areas+menuitems) ?

beverages
coffee

would be ID = 1-4

You would then explode the ID by the - and get area and menuitem

Maybe i'm getting wrongly what you ask, but it seems that it might work.

jmDesktop wrote:
I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.

I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,

table areas
id 1 areaname beverages
id 2 areaname grill

table menuitems

id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger

Now, in my form, I have the entire menu displayed with all areas and
menu items. In each area there is small set of textboxes to enter new
menuitems for that area with a button. Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. I know
I've lost you. Let me try again.

In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. These are generated
by a set of loops from my database.

Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:

myprocessor.php?id=3&item=coke&id=4&item=0.... I just get a
querystring with lots of blank variables. I know I must be doing
something to have this. All I really need is one ID. The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. Thank you.
Sep 14 '08 #2
On 14 Sep, 00:37, jmDesktop <needin4mat...@gmail.comwrote:
I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.

I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,

table areas
id 1 areaname beverages
id 2 areaname grill

table menuitems

id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
<snip>
>
Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:
don't use 'name' - use 'name[]' and PHP will assign array indices
automtically. But you'll need to do some testing around this if more
than one is added at a time to multiple fields.

C.
Sep 14 '08 #3
C. (http://symcbean.blogspot.com/) wrote:
On 14 Sep, 00:37, jmDesktop <needin4mat...@gmail.comwrote:
>I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.

I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,

table areas
id 1 areaname beverages
id 2 areaname grill

table menuitems

id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
<snip>
>Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:

don't use 'name' - use 'name[]' and PHP will assign array indices
automtically. But you'll need to do some testing around this if more
than one is added at a time to multiple fields.

C.
Or, what you can do is have the form use post and simply have a test on
the value of the submit button. You could have the value of those
sumbit buttons be "Add Beverage", "Add Entree" etc. That would tell you
the area that it is coming from by which button was pressed.

Since you now have a long URL listed, you are obviously using method
get. What are you currently doing to produce that very long URL? Does
each of the buttons have an exrremely long onclick, with each field
being filled by something like a
document.getElementById('the_name'),value? Are you using a javascript
function to get and build that string and then doing a submit from
there? If either of these, it is very easy to just limit the url and in
the receiving script test to see which was changed. Why, you could even
add a "director" field to indicate this and switch on that field to
extract the actual value from the URL via a $_GET.

There are many way to get what you want. You have been given several
suggestions here and by previous responders. My suggestion is getrid of
all those parameters in the URL and change to a method=post.

Sep 14 '08 #4
sheldonlg wrote:
C. (http://symcbean.blogspot.com/) wrote:
>On 14 Sep, 00:37, jmDesktop <needin4mat...@gmail.comwrote:
>>I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.

I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,

table areas
id 1 areaname beverages
id 2 areaname grill

table menuitems

id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
<snip>
>>Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:

don't use 'name' - use 'name[]' and PHP will assign array indices
automtically. But you'll need to do some testing around this if more
than one is added at a time to multiple fields.

C.

Or, what you can do is have the form use post and simply have a test on
the value of the submit button. You could have the value of those
sumbit buttons be "Add Beverage", "Add Entree" etc. That would tell you
the area that it is coming from by which button was pressed.

Since you now have a long URL listed, you are obviously using method
get. What are you currently doing to produce that very long URL? Does
each of the buttons have an exrremely long onclick, with each field
being filled by something like a
document.getElementById('the_name'),value? Are you using a javascript
function to get and build that string and then doing a submit from
there? If either of these, it is very easy to just limit the url and in
the receiving script test to see which was changed. Why, you could even
add a "director" field to indicate this and switch on that field to
extract the actual value from the URL via a $_GET.

There are many way to get what you want. You have been given several
suggestions here and by previous responders. My suggestion is getrid of
all those parameters in the URL and change to a method=post.
Another comment:

From the OP's description, it seems that this is a natural fit for
AJAX. The user would click on a particular button, it would use an
onclick to pass in the the correct info to the javascript function. The
call to php would do an insert of that pair and on a return from php
would update that region and blank the text area. The user would remain
on the menu page.
Sep 14 '08 #5
jmDesktop wrote:
I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.

I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,

table areas
id 1 areaname beverages
id 2 areaname grill

table menuitems

id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger

Now, in my form, I have the entire menu displayed with all areas and
menu items. In each area there is small set of textboxes to enter new
menuitems for that area with a button. Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. I know
I've lost you. Let me try again.

In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. These are generated
by a set of loops from my database.

Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:

myprocessor.php?id=3&item=coke&id=4&item=0.... I just get a
querystring with lots of blank variables. I know I must be doing
something to have this. All I really need is one ID. The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. Thank you.
Yes, this is a problem. Probably the best way to handle it is to give
each text area a different name - i.e. "new_beverage", "new_grill", etc.
Then when the form gets submitted, check each area to see that it is
not empty. An advantage of this over individual forms is you can add
multiple items (one of each) at once.

You could even name the text areas new_beverage[], new_grill[], etc. and
have multiple of each on the page. If you had three of each, you could
add up to three of each item on every page.

Alternatives such as having separate forms for each section or having
"Add Beverage", "Add Grill", etc. buttons limit you to being able to add
a single item each time. That may be ok, but if you have a lot of items
to add to a menu, it can get old real fast.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 14 '08 #6
On Sep 14, 6:59*am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
On 14 Sep, 00:37, jmDesktop <needin4mat...@gmail.comwrote:


I have a food menu. *Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.
I want to add a new drink to beverages. *In my database I have an
"area" like above, Bevs, Grill, Chicken... *In my menu items I have an
ID from the area so,
table areas
id 1 areaname beverages
id 2 areaname grill
table menuitems
id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
<snip>
Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:

don't use 'name' - use 'name[]' and PHP will assign array indices
automtically. But you'll need to do some testing around this if more
than one is added at a time to multiple fields.

C.- Hide quoted text -

- Show quoted text -
use name[] where? Sorry. Never done that before.
Sep 15 '08 #7
On Sep 13, 8:04*pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.orgwrote:
hello

Why not make a <FORMfor every area? that way you will only get a set
of values for that area.

For instance <FORM for beveragesand <FORM for grilleach with a
separate SUBMIT button?

why not use the POST method instead of the GET?

Why not use a special ID for each field (areas+menuitems) ?

beverages
* *coffee

would be ID = 1-4

You would then explode the ID by the - and get area and menuitem

Maybe i'm getting wrongly what you ask, but it seems that it might work.

jmDesktop wrote:
I have a food menu. *Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.
I want to add a new drink to beverages. *In my database I have an
"area" like above, Bevs, Grill, Chicken... *In my menu items I have an
ID from the area so,
table areas
id 1 areaname beverages
id 2 areaname grill
table menuitems
id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
Now, in my form, I have the entire menu displayed with all areas and
menu items. *In each area there is small set of textboxes to enter new
menuitems for that area with a button. *Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. *it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. *I know
I've lost you. *Let me try again.
In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. *Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. *These are generated
by a set of loops from my database.
Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:
myprocessor.php?id=3&item=coke&id=4&item=0.... *I just get a
querystring with lots of blank variables. *I know I must be doing
something to have this. *All I really need is one ID. *The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. *Thank you..- Hide quoted text -

- Show quoted text -
Thanks. I didn't know you could have more than one form on a page. I
guess that is from my .NET.
Sep 15 '08 #8
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.orgwrote:
>hello

Why not make a <FORMfor every area? that way you will only get a set
of values for that area.

For instance <FORM for beveragesand <FORM for grilleach with a
separate SUBMIT button?

why not use the POST method instead of the GET?

Why not use a special ID for each field (areas+menuitems) ?

beverages
coffee

would be ID = 1-4

You would then explode the ID by the - and get area and menuitem

Maybe i'm getting wrongly what you ask, but it seems that it might work.

jmDesktop wrote:
>>I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.
I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,
table areas
id 1 areaname beverages
id 2 areaname grill
table menuitems
id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
Now, in my form, I have the entire menu displayed with all areas and
menu items. In each area there is small set of textboxes to enter new
menuitems for that area with a button. Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. I know
I've lost you. Let me try again.
In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. These are generated
by a set of loops from my database.
Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:
myprocessor.php?id=3&item=coke&id=4&item=0.... I just get a
querystring with lots of blank variables. I know I must be doing
something to have this. All I really need is one ID. The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. Thank you.- Hide quoted text -
- Show quoted text -

Thanks. I didn't know you could have more than one form on a page. I
guess that is from my .NET.
No, that's from the poor tools .NET has.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 15 '08 #9
On Sep 15, 9:23*am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.orgwrote:
hello
Why not make a <FORMfor every area? that way you will only get a set
of values for that area.
For instance <FORM for beveragesand <FORM for grilleach with a
separate SUBMIT button?
why not use the POST method instead of the GET?
Why not use a special ID for each field (areas+menuitems) ?
beverages
* *coffee
would be ID = 1-4
You would then explode the ID by the - and get area and menuitem
Maybe i'm getting wrongly what you ask, but it seems that it might work.
jmDesktop wrote:
I have a food menu. *Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.
I want to add a new drink to beverages. *In my database I have an
"area" like above, Bevs, Grill, Chicken... *In my menu items I havean
ID from the area so,
table areas
id 1 areaname beverages
id 2 areaname grill
table menuitems
id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
Now, in my form, I have the entire menu displayed with all areas and
menu items. *In each area there is small set of textboxes to enter new
menuitems for that area with a button. *Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. *it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. *I know
I've lost you. *Let me try again.
In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. *Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. *These are generated
by a set of loops from my database.
Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:
myprocessor.php?id=3&item=coke&id=4&item=0.... *I just get a
querystring with lots of blank variables. *I know I must be doing
something to have this. *All I really need is one ID. *The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. *Thank you.- Hide quoted text -
- Show quoted text -
Thanks. *I didn't know you could have more than one form on a page. *I
guess that is from my .NET.

No, that's from the poor tools .NET has.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
How do I use the [] with a form element? thank you.
Sep 15 '08 #10
jmDesktop wrote:
I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.
I'm confused by what you are doing but I think you have multiple rows
from your database and you want to update that.

You can use many forms as has been indicated, and update one row at a
time (a form for each row, with it's id).

Or if you need to update all of them, you can prepend the ID to the
form element name, such that:

my_form_name, with an id of 12
becomes:
12my_form_name

use a regex to parse out the id and field name.

/(\d*)(.*)/

That implies, of course, that you have an auto increment ID and no
starting number in your field name (IMHO, that's a good idea anyways).
Otherwise you'll need a different scheme.

I usually embed the id like that in a hidden field, parse out the ID
and then update that row (many fields) in one swoop and then all the rows:

// from something I wrote a few days ago

foreach($_POST as $item){

if(preg_match("/id_(.*)/",$item,$MATCHES)){
$id_ = $MATCHES[1];

$sth->execute(array($_POST[$id_ . 'some_field'],$_POST[$id_ .
'some_other_field']...

YMMV. I'm sure there's many ways to do this.

Jeff


>
I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,

table areas
id 1 areaname beverages
id 2 areaname grill

table menuitems

id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger

Now, in my form, I have the entire menu displayed with all areas and
menu items. In each area there is small set of textboxes to enter new
menuitems for that area with a button. Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. I know
I've lost you. Let me try again.

In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. These are generated
by a set of loops from my database.

Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:

myprocessor.php?id=3&item=coke&id=4&item=0.... I just get a
querystring with lots of blank variables. I know I must be doing
something to have this. All I really need is one ID. The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. Thank you.
Sep 15 '08 #11
jmDesktop wrote:
On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.orgwrote:
hello
Why not make a <FORMfor every area? that way you will only get a set
of values for that area.
For instance <FORM for beveragesand <FORM for grilleach with a
separate SUBMIT button?
why not use the POST method instead of the GET?
Why not use a special ID for each field (areas+menuitems) ?
beverages
coffee
would be ID = 1-4
You would then explode the ID by the - and get area and menuitem
Maybe i'm getting wrongly what you ask, but it seems that it might work.
jmDesktop wrote:
I have a food menu. Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.
I want to add a new drink to beverages. In my database I have an
"area" like above, Bevs, Grill, Chicken... In my menu items I have an
ID from the area so,
table areas
id 1 areaname beverages
id 2 areaname grill
table menuitems
id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
Now, in my form, I have the entire menu displayed with all areas and
menu items. In each area there is small set of textboxes to enter new
menuitems for that area with a button. Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. I know
I've lost you. Let me try again.
In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. Underneath this I have
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. These are generated
by a set of loops from my database.
Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:
myprocessor.php?id=3&item=coke&id=4&item=0.. .. I just get a
querystring with lots of blank variables. I know I must be doing
something to have this. All I really need is one ID. The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. Thank you.- Hide quoted text -
- Show quoted text -
Thanks. I didn't know you could have more than one form on a page. I
guess that is from my .NET.
No, that's from the poor tools .NET has.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

How do I use the [] with a form element? thank you.
<input name="myval[]" ...>

This will create an array called myval as an element of the $_GET or
$_POST array, depending on whether your form method is get or post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 15 '08 #12
On Sep 15, 7:43*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.orgwrote:
hello
Why not make a <FORMfor every area? that way you will only get a set
of values for that area.
For instance <FORM for beveragesand <FORM for grilleach with a
separate SUBMIT button?
why not use the POST method instead of the GET?
Why not use a special ID for each field (areas+menuitems) ?
beverages
* *coffee
would be ID = 1-4
You would then explode the ID by the - and get area and menuitem
Maybe i'm getting wrongly what you ask, but it seems that it might work.
jmDesktop wrote:
I have a food menu. *Each area, like beverages, grill, etc. have items
under them, Coke, Tea, Coffee would be under beverages for example.
I want to add a new drink to beverages. *In my database I have an
"area" like above, Bevs, Grill, Chicken... *In my menu items I have an
ID from the area so,
table areas
id 1 areaname beverages
id 2 areaname grill
table menuitems
id 1 areaid 1 menuitem coke
id 2 areaid 1 menuitem sprite
id 3 areaid 2 menuitem hamburger
Now, in my form, I have the entire menu displayed with all areas and
menu items. *In each area there is small set of textboxes to enter new
menuitems for that area with a button. *Messy yes, but what I can't
figure out how to do is get the unique table area id for the new menu
item because when the user clicks submit it doesn't just send the
"name" across for that particular area addition. *it sends all the
form elements over and since they are all named the same thing I have
tons of them and I don't know how to get just that unique id. *I know
I've lost you. *Let me try again.
In the display I have beverages and right underneath it has a textbox
for a new item and next to that a save button. *Underneath this Ihave
grill and right underneath it has a textbox for a new itema and next
to that a save button and so on with ever area. *These are generated
by a set of loops from my database.
Since all the textboxes have the same "name" attribute when I click
save I get many many identical attributes:
myprocessor.php?id=3&item=coke&id=4&item=0... . *I just get a
querystring with lots of blank variables. *I know I must be doing
something to have this. *All I really need is one ID. *The ID from the
current area and that textbox only, but I can't since all the
generated elements are in between the same <formelement. *Thankyou.- Hide quoted text -
- Show quoted text -
Thanks. *I didn't know you could have more than one form on a page.*I
guess that is from my .NET.
No, that's from the poor tools .NET has.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
How do I use the *[] with a form element? *thank you.

<input name="myval[]" ...>

This will create an array called myval as an element of the $_GET or
$_POST array, depending on whether your form method is get or post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
How do I know what to look for on the php side if they all have the
name myval[]?
Sep 16 '08 #13
jmDesktop wrote:
On Sep 15, 7:43 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.orgwrote:
>hello
>Why not make a <FORMfor every area? that way you will only get a set
>of values for that area.
>For instance <FORM for beveragesand <FORM for grilleach with a
>separate SUBMIT button?
>why not use the POST method instead of the GET?
>Why not use a special ID for each field (areas+menuitems) ?
>beverages
> coffee
>would be ID = 1-4
>You would then explode the ID by the - and get area and menuitem
>Maybe i'm getting wrongly what you ask, but it seems that it might work.
>jmDesktop wrote:
>>I have a food menu. Each area, like beverages, grill, etc. have items
>>under them, Coke, Tea, Coffee would be under beverages for example.
>>I want to add a new drink to beverages. In my database I have an
>>"area" like above, Bevs, Grill, Chicken... In my menu items I have an
>>ID from the area so,
>>table areas
>>id 1 areaname beverages
>>id 2 areaname grill
>>table menuitems
>>id 1 areaid 1 menuitem coke
>>id 2 areaid 1 menuitem sprite
>>id 3 areaid 2 menuitem hamburger
>>Now, in my form, I have the entire menu displayed with all areas and
>>menu items. In each area there is small set of textboxes to enter new
>>menuitems for that area with a button. Messy yes, but what I can't
>>figure out how to do is get the unique table area id for the new menu
>>item because when the user clicks submit it doesn't just send the
>>"name" across for that particular area addition. it sends all the
>>form elements over and since they are all named the same thing I have
>>tons of them and I don't know how to get just that unique id. I know
>>I've lost you. Let me try again.
>>In the display I have beverages and right underneath it has a textbox
>>for a new item and next to that a save button. Underneath this I have
>>grill and right underneath it has a textbox for a new itema and next
>>to that a save button and so on with ever area. These are generated
>>by a set of loops from my database.
>>Since all the textboxes have the same "name" attribute when I click
>>save I get many many identical attributes:
>>myprocessor.php?id=3&item=coke&id=4&item=0.. .. I just get a
>>querystring with lots of blank variables. I know I must be doing
>>something to have this. All I really need is one ID. The ID from the
>>current area and that textbox only, but I can't since all the
>>generated elements are in between the same <formelement. Thank you.- Hide quoted text -
>- Show quoted text -
Thanks. I didn't know you could have more than one form on a page. I
guess that is from my .NET.
No, that's from the poor tools .NET has.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
How do I use the [] with a form element? thank you.
<input name="myval[]" ...>

This will create an array called myval as an element of the $_GET or
$_POST array, depending on whether your form method is get or post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

How do I know what to look for on the php side if they all have the
name myval[]?
It will be an array on the PHP side, i.e.

$_POST['myval'][0]
$_POST['myval'][1]
$_POST['myval'][2]

etc.

The value will be whatever the value of the element is, i.e. the value=
for a checkbox, and the text in an input field.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 16 '08 #14
jmDesktop wrote:
On Sep 15, 7:43 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 15, 9:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
jmDesktop wrote:
On Sep 13, 8:04 pm, "RootShell (IFReviews.org)"
<rootsh...@ifreviews.orgwrote:
>hello
>Why not make a <FORMfor every area? that way you will only get a set
>of values for that area.
>For instance <FORM for beveragesand <FORM for grilleach with a
>separate SUBMIT button?
>why not use the POST method instead of the GET?
>Why not use a special ID for each field (areas+menuitems) ?
>beverages
> coffee
>would be ID = 1-4
>You would then explode the ID by the - and get area and menuitem
>Maybe i'm getting wrongly what you ask, but it seems that it might work.
>jmDesktop wrote:
>>I have a food menu. Each area, like beverages, grill, etc. have items
>>under them, Coke, Tea, Coffee would be under beverages for example.
>>I want to add a new drink to beverages. In my database I have an
>>"area" like above, Bevs, Grill, Chicken... In my menu items I have an
>>ID from the area so,
>>table areas
>>id 1 areaname beverages
>>id 2 areaname grill
>>table menuitems
>>id 1 areaid 1 menuitem coke
>>id 2 areaid 1 menuitem sprite
>>id 3 areaid 2 menuitem hamburger
>>Now, in my form, I have the entire menu displayed with all areas and
>>menu items. In each area there is small set of textboxes to enter new
>>menuitems for that area with a button. Messy yes, but what I can't
>>figure out how to do is get the unique table area id for the new menu
>>item because when the user clicks submit it doesn't just send the
>>"name" across for that particular area addition. it sends all the
>>form elements over and since they are all named the same thing I have
>>tons of them and I don't know how to get just that unique id. I know
>>I've lost you. Let me try again.
>>In the display I have beverages and right underneath it has a textbox
>>for a new item and next to that a save button. Underneath this I have
>>grill and right underneath it has a textbox for a new itema and next
>>to that a save button and so on with ever area. These are generated
>>by a set of loops from my database.
>>Since all the textboxes have the same "name" attribute when I click
>>save I get many many identical attributes:
>>myprocessor.php?id=3&item=coke&id=4&item=0.. .. I just get a
>>querystring with lots of blank variables. I know I must be doing
>>something to have this. All I really need is one ID. The ID from the
>>current area and that textbox only, but I can't since all the
>>generated elements are in between the same <formelement. Thank you.- Hide quoted text -
>- Show quoted text -
Thanks. I didn't know you could have more than one form on a page. I
guess that is from my .NET.
No, that's from the poor tools .NET has.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
How do I use the [] with a form element? thank you.
<input name="myval[]" ...>

This will create an array called myval as an element of the $_GET or
$_POST array, depending on whether your form method is get or post.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

How do I know what to look for on the php side if they all have the
name myval[]?
To elaborate just a bit on this.

some_array[] just adds on to the end of the array. If you are familiar
with push from other languages, it does the same thing.

Jeff
Sep 16 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Howard Jess | last post by:
Apparently, form elements of type <input type="image" src="...> are not included in the form's elements collection. I don't understand why not; according to DOM2, all form control elements...
2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
46
by: vvk4 | last post by:
I have an excel spreadsheet that I need to parse. I was thinking of saving this as a CSV file. And then reading the file using C. The actual in EXCEL looks like: a,b a"b a","b a,",b In CSV...
10
by: Drakier Dominaeus | last post by:
This is my first time posting here, so please forgive me if I do anything incorrectly. I've been learning C# and working with different things and decided I wanted to get into Multi-Threading....
3
by: Kevin Kenny | last post by:
Dear All, I have a date time validation method thus: public static bool IsDate(string date, System.IFormatProvider provider) { try { DateTime.Parse(date, provider) return true; } catch...
25
by: Dave | last post by:
Hello. In trying to get an anchor element to stylistically match an input or button element, I find that the button and input cannot be styled according to the 2.1 CSS spec. For example, I...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
10
by: Andy B | last post by:
If I have the following text in a dataset table column: "This agreement establishes that {BandName} will play on {EventDate} between {StartTime} and {EndTime}..." How would I then take the field...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.